package cn.jiguang.cordova.push; import android.app.Activity; import android.app.AppOpsManager; import android.app.NotificationManager; import android.content.Context; import android.content.pm.ApplicationInfo; import android.os.Build; import android.text.TextUtils; import android.util.Log; import cn.jpush.android.api.BasicPushNotificationBuilder; import cn.jpush.android.api.JPushInterface; import cn.jpush.android.api.TagAliasCallback; import cn.jpush.android.data.JPushLocalNotification; import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaInterface; import org.apache.cordova.CordovaPlugin; import org.apache.cordova.CordovaWebView; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class JPushPlugin extends CordovaPlugin { private static final String TAG = "JPushPlugin"; private static Activity cordovaActivity; static Map<Integer, CallbackContext> eventCallbackMap = new HashMap(); private static JPushPlugin instance; static String notificationAlert; static Map<String, Object> notificationExtras = new HashMap(); static String notificationTitle; static String openNotificationAlert; static Map<String, Object> openNotificationExtras = new HashMap(); static String openNotificationTitle; private Context mContext; private final TagAliasCallback mTagWithAliasCallback = new TagAliasCallback() { /* class cn.jiguang.cordova.push.JPushPlugin.AnonymousClass6 */ @Override // cn.jpush.android.api.TagAliasCallback public void gotResult(int i, String str, Set<String> set) { if (JPushPlugin.instance != null) { JSONObject jSONObject = new JSONObject(); try { jSONObject.put("resultCode", i); jSONObject.put("tags", set); jSONObject.put("alias", str); final String format = String.format("cordova.fireDocumentEvent('jpush.setTagsWithAlias',%s)", jSONObject.toString()); JPushPlugin.this.f0cordova.getActivity().runOnUiThread(new Runnable() { /* class cn.jiguang.cordova.push.JPushPlugin.AnonymousClass6.AnonymousClass1 */ public void run() { CordovaWebView cordovaWebView = JPushPlugin.instance.webView; cordovaWebView.loadUrl("javascript:" + format); } }); } catch (JSONException e) { e.printStackTrace(); } } } }; private boolean isValidHour(int i) { return i >= 0 && i <= 23; } private boolean isValidMinute(int i) { return i >= 0 && i <= 59; } /* access modifiers changed from: package-private */ public void setCustomPushNotificationBuilder(JSONArray jSONArray, CallbackContext callbackContext) { } public JPushPlugin() { instance = this; } @Override // org.apache.cordova.CordovaPlugin public void initialize(CordovaInterface cordovaInterface, CordovaWebView cordovaWebView) { super.initialize(cordovaInterface, cordovaWebView); this.mContext = cordovaInterface.getActivity().getApplicationContext(); JPushInterface.init(this.mContext); cordovaActivity = cordovaInterface.getActivity(); String str = openNotificationAlert; if (str != null) { notificationAlert = null; transmitNotificationOpen(openNotificationTitle, str, openNotificationExtras); } String str2 = notificationAlert; if (str2 != null) { transmitNotificationReceive(notificationTitle, str2, notificationExtras); } } @Override // org.apache.cordova.CordovaPlugin public void onResume(boolean z) { String str = openNotificationAlert; if (str != null) { notificationAlert = null; transmitNotificationOpen(openNotificationTitle, str, openNotificationExtras); } String str2 = notificationAlert; if (str2 != null) { transmitNotificationReceive(notificationTitle, str2, notificationExtras); } } @Override // org.apache.cordova.CordovaPlugin public void onDestroy() { super.onDestroy(); cordovaActivity = null; instance = null; } private static JSONObject getMessageObject(String str, Map<String, Object> map) { JSONObject jSONObject; JSONObject jSONObject2 = new JSONObject(); try { jSONObject2.put("message", str); JSONObject jSONObject3 = new JSONObject(); for (Map.Entry<String, Object> entry : map.entrySet()) { if (entry.getKey().equals(JPushInterface.EXTRA_EXTRA)) { if (TextUtils.isEmpty((String) entry.getValue())) { jSONObject = new JSONObject(); } else { JSONObject jSONObject4 = new JSONObject((String) entry.getValue()); Iterator<String> keys = jSONObject4.keys(); while (keys.hasNext()) { String obj = keys.next().toString(); jSONObject3.put(obj, jSONObject4.getString(obj)); } jSONObject = jSONObject4; } jSONObject3.put(JPushInterface.EXTRA_EXTRA, jSONObject); } else { jSONObject3.put(entry.getKey(), entry.getValue()); } } if (jSONObject3.length() > 0) { jSONObject2.put("extras", jSONObject3); } } catch (JSONException e) { e.printStackTrace(); } return jSONObject2; } private static JSONObject getNotificationObject(String str, String str2, Map<String, Object> map) { JSONObject jSONObject; JSONObject jSONObject2 = new JSONObject(); try { jSONObject2.put("title", str); jSONObject2.put("alert", str2); JSONObject jSONObject3 = new JSONObject(); for (Map.Entry<String, Object> entry : map.entrySet()) { if (entry.getKey().equals(JPushInterface.EXTRA_EXTRA)) { if (TextUtils.isEmpty((String) entry.getValue())) { jSONObject = new JSONObject(); } else { JSONObject jSONObject4 = new JSONObject((String) entry.getValue()); Iterator<String> keys = jSONObject4.keys(); while (keys.hasNext()) { String obj = keys.next().toString(); jSONObject3.put(obj, jSONObject4.getString(obj)); } jSONObject = jSONObject4; } jSONObject3.put(JPushInterface.EXTRA_EXTRA, jSONObject); } else { jSONObject3.put(entry.getKey(), entry.getValue()); } } if (jSONObject3.length() > 0) { jSONObject2.put("extras", jSONObject3); } } catch (JSONException e) { e.printStackTrace(); } return jSONObject2; } static void transmitMessageReceive(String str, Map<String, Object> map) { if (instance != null) { final String format = String.format("window.plugins.jPushPlugin.receiveMessageInAndroidCallback(%s);", getMessageObject(str, map).toString()); cordovaActivity.runOnUiThread(new Runnable() { /* class cn.jiguang.cordova.push.JPushPlugin.AnonymousClass1 */ public void run() { CordovaWebView cordovaWebView = JPushPlugin.instance.webView; cordovaWebView.loadUrl("javascript:" + format); } }); } } static void transmitNotificationOpen(String str, String str2, Map<String, Object> map) { if (instance != null) { final String format = String.format("window.plugins.jPushPlugin.openNotificationInAndroidCallback(%s);", getNotificationObject(str, str2, map).toString()); cordovaActivity.runOnUiThread(new Runnable() { /* class cn.jiguang.cordova.push.JPushPlugin.AnonymousClass2 */ public void run() { CordovaWebView cordovaWebView = JPushPlugin.instance.webView; cordovaWebView.loadUrl("javascript:" + format); } }); openNotificationTitle = null; openNotificationAlert = null; } } static void transmitNotificationReceive(String str, String str2, Map<String, Object> map) { if (instance != null) { final String format = String.format("window.plugins.jPushPlugin.receiveNotificationInAndroidCallback(%s);", getNotificationObject(str, str2, map).toString()); cordovaActivity.runOnUiThread(new Runnable() { /* class cn.jiguang.cordova.push.JPushPlugin.AnonymousClass3 */ public void run() { CordovaWebView cordovaWebView = JPushPlugin.instance.webView; cordovaWebView.loadUrl("javascript:" + format); } }); notificationTitle = null; notificationAlert = null; } } static void transmitReceiveRegistrationId(String str) { if (instance != null) { JSONObject jSONObject = new JSONObject(); try { jSONObject.put("registrationId", str); } catch (JSONException e) { e.printStackTrace(); } final String format = String.format("window.plugins.jPushPlugin.receiveRegistrationIdInAndroidCallback(%s);", jSONObject.toString()); cordovaActivity.runOnUiThread(new Runnable() { /* class cn.jiguang.cordova.push.JPushPlugin.AnonymousClass4 */ public void run() { CordovaWebView cordovaWebView = JPushPlugin.instance.webView; cordovaWebView.loadUrl("javascript:" + format); } }); } } @Override // org.apache.cordova.CordovaPlugin public boolean execute(final String str, final JSONArray jSONArray, final CallbackContext callbackContext) throws JSONException { this.f0cordova.getThreadPool().execute(new Runnable() { /* class cn.jiguang.cordova.push.JPushPlugin.AnonymousClass5 */ public void run() { try { JPushPlugin.class.getDeclaredMethod(str, JSONArray.class, CallbackContext.class).invoke(JPushPlugin.this, jSONArray, callbackContext); } catch (Exception e) { Log.e(JPushPlugin.TAG, e.toString()); } } }); return true; } /* access modifiers changed from: package-private */ public void init(JSONArray jSONArray, CallbackContext callbackContext) { JPushInterface.init(this.mContext); } /* access modifiers changed from: package-private */ public void setDebugMode(JSONArray jSONArray, CallbackContext callbackContext) { try { JPushInterface.setDebugMode(jSONArray.getBoolean(0)); callbackContext.success(); } catch (JSONException e) { e.printStackTrace(); } } /* access modifiers changed from: package-private */ public void stopPush(JSONArray jSONArray, CallbackContext callbackContext) { JPushInterface.stopPush(this.mContext); callbackContext.success(); } /* access modifiers changed from: package-private */ public void resumePush(JSONArray jSONArray, CallbackContext callbackContext) { JPushInterface.resumePush(this.mContext); callbackContext.success(); } /* access modifiers changed from: package-private */ public void isPushStopped(JSONArray jSONArray, CallbackContext callbackContext) { if (JPushInterface.isPushStopped(this.mContext)) { callbackContext.success(1); } else { callbackContext.success(0); } } /* access modifiers changed from: package-private */ public void areNotificationEnabled(JSONArray jSONArray, CallbackContext callbackContext) { callbackContext.success(hasPermission("OP_POST_NOTIFICATION") ? 1 : 0); } /* access modifiers changed from: package-private */ public void setLatestNotificationNum(JSONArray jSONArray, CallbackContext callbackContext) { int i; try { i = jSONArray.getInt(0); } catch (JSONException e) { e.printStackTrace(); callbackContext.error("error reading num json"); i = -1; } if (i != -1) { JPushInterface.setLatestNotificationNumber(this.mContext, i); } else { callbackContext.error("error num"); } } /* access modifiers changed from: package-private */ public void setPushTime(JSONArray jSONArray, CallbackContext callbackContext) { int i; HashSet hashSet = new HashSet(); try { JSONArray jSONArray2 = jSONArray.getJSONArray(0); for (int i2 = 0; i2 < jSONArray2.length(); i2++) { hashSet.add(Integer.valueOf(jSONArray2.getInt(i2))); } } catch (JSONException e) { e.printStackTrace(); callbackContext.error("error reading days json"); } int i3 = -1; try { i = jSONArray.getInt(1); try { i3 = jSONArray.getInt(2); } catch (JSONException unused) { } } catch (JSONException unused2) { i = -1; callbackContext.error("error reading hour json"); JPushInterface.setPushTime(this.mContext, hashSet, i, i3); callbackContext.success(); } JPushInterface.setPushTime(this.mContext, hashSet, i, i3); callbackContext.success(); } /* access modifiers changed from: package-private */ public void getRegistrationID(JSONArray jSONArray, CallbackContext callbackContext) { callbackContext.success(JPushInterface.getRegistrationID(this.mContext)); } /* access modifiers changed from: package-private */ public void onResume(JSONArray jSONArray, CallbackContext callbackContext) { JPushInterface.onResume(this.f0cordova.getActivity()); } /* access modifiers changed from: package-private */ public void onPause(JSONArray jSONArray, CallbackContext callbackContext) { JPushInterface.onPause(this.f0cordova.getActivity()); } /* access modifiers changed from: package-private */ public void reportNotificationOpened(JSONArray jSONArray, CallbackContext callbackContext) { try { JPushInterface.reportNotificationOpened(this.f0cordova.getActivity(), jSONArray.getString(0)); } catch (JSONException e) { e.printStackTrace(); } } /* access modifiers changed from: package-private */ public void setAlias(JSONArray jSONArray, CallbackContext callbackContext) { String str; int i = -1; try { JSONObject jSONObject = jSONArray.getJSONObject(0); i = jSONObject.getInt("sequence"); str = jSONObject.getString("alias"); } catch (JSONException e) { e.printStackTrace(); callbackContext.error("Parameters error."); str = null; } JPushInterface.setAlias(this.mContext, i, str); eventCallbackMap.put(Integer.valueOf(i), callbackContext); } /* access modifiers changed from: package-private */ public void deleteAlias(JSONArray jSONArray, CallbackContext callbackContext) { int i; try { i = jSONArray.getJSONObject(0).getInt("sequence"); } catch (JSONException e) { e.printStackTrace(); callbackContext.error("Parameters error."); i = -1; } JPushInterface.deleteAlias(this.mContext, i); eventCallbackMap.put(Integer.valueOf(i), callbackContext); } /* access modifiers changed from: package-private */ public void getAlias(JSONArray jSONArray, CallbackContext callbackContext) { int i; try { i = jSONArray.getJSONObject(0).getInt("sequence"); } catch (JSONException e) { e.printStackTrace(); callbackContext.error("Parameters error."); i = -1; } JPushInterface.getAlias(this.mContext, i); eventCallbackMap.put(Integer.valueOf(i), callbackContext); } /* access modifiers changed from: package-private */ public void setTags(JSONArray jSONArray, CallbackContext callbackContext) { HashSet hashSet = new HashSet(); int i = -1; try { JSONObject jSONObject = jSONArray.getJSONObject(0); i = jSONObject.getInt("sequence"); JSONArray jSONArray2 = jSONObject.getJSONArray("tags"); for (int i2 = 0; i2 < jSONArray2.length(); i2++) { hashSet.add(jSONArray2.getString(i2)); } } catch (JSONException e) { e.printStackTrace(); callbackContext.error("Parameters error."); } JPushInterface.setTags(this.mContext, i, hashSet); eventCallbackMap.put(Integer.valueOf(i), callbackContext); } /* access modifiers changed from: package-private */ public void addTags(JSONArray jSONArray, CallbackContext callbackContext) { HashSet hashSet = new HashSet(); int i = -1; try { JSONObject jSONObject = jSONArray.getJSONObject(0); i = jSONObject.getInt("sequence"); JSONArray jSONArray2 = jSONObject.getJSONArray("tags"); for (int i2 = 0; i2 < jSONArray2.length(); i2++) { hashSet.add(jSONArray2.getString(i2)); } } catch (JSONException e) { e.printStackTrace(); callbackContext.error("Parameters error."); } JPushInterface.addTags(this.mContext, i, hashSet); eventCallbackMap.put(Integer.valueOf(i), callbackContext); } /* access modifiers changed from: package-private */ public void deleteTags(JSONArray jSONArray, CallbackContext callbackContext) { HashSet hashSet = new HashSet(); int i = -1; try { JSONObject jSONObject = jSONArray.getJSONObject(0); i = jSONObject.getInt("sequence"); JSONArray jSONArray2 = jSONObject.getJSONArray("tags"); for (int i2 = 0; i2 < jSONArray2.length(); i2++) { hashSet.add(jSONArray2.getString(i2)); } } catch (JSONException e) { e.printStackTrace(); callbackContext.error("Parameters error."); } JPushInterface.deleteTags(this.mContext, i, hashSet); eventCallbackMap.put(Integer.valueOf(i), callbackContext); } /* access modifiers changed from: package-private */ public void cleanTags(JSONArray jSONArray, CallbackContext callbackContext) { int i; try { i = jSONArray.getJSONObject(0).getInt("sequence"); } catch (JSONException e) { e.printStackTrace(); callbackContext.error("Parameters error."); i = -1; } JPushInterface.cleanTags(this.mContext, i); eventCallbackMap.put(Integer.valueOf(i), callbackContext); } /* access modifiers changed from: package-private */ public void getAllTags(JSONArray jSONArray, CallbackContext callbackContext) { int i; try { i = jSONArray.getJSONObject(0).getInt("sequence"); } catch (JSONException e) { e.printStackTrace(); callbackContext.error("Parameters error."); i = -1; } JPushInterface.getAllTags(this.mContext, i); eventCallbackMap.put(Integer.valueOf(i), callbackContext); } /* access modifiers changed from: package-private */ public void checkTagBindState(JSONArray jSONArray, CallbackContext callbackContext) { String str; int i = -1; try { JSONObject jSONObject = jSONArray.getJSONObject(0); i = jSONObject.getInt("sequence"); str = jSONObject.getString("tag"); } catch (JSONException e) { e.printStackTrace(); callbackContext.error("Parameters error."); str = null; } JPushInterface.checkTagBindState(this.mContext, i, str); eventCallbackMap.put(Integer.valueOf(i), callbackContext); } /* access modifiers changed from: package-private */ public void getConnectionState(JSONArray jSONArray, CallbackContext callbackContext) { if (JPushInterface.getConnectionState(cordovaActivity.getApplicationContext())) { callbackContext.success(1); } else { callbackContext.success(0); } } /* access modifiers changed from: package-private */ public void setBasicPushNotificationBuilder(JSONArray jSONArray, CallbackContext callbackContext) { BasicPushNotificationBuilder basicPushNotificationBuilder = new BasicPushNotificationBuilder(this.f0cordova.getActivity()); basicPushNotificationBuilder.developerArg0 = "Basic builder 1"; JPushInterface.setPushNotificationBuilder(1, basicPushNotificationBuilder); try { new JSONObject().put("id", 1); } catch (JSONException e) { e.printStackTrace(); } } /* access modifiers changed from: package-private */ public void clearAllNotification(JSONArray jSONArray, CallbackContext callbackContext) { JPushInterface.clearAllNotifications(this.f0cordova.getActivity()); } /* access modifiers changed from: package-private */ public void clearNotificationById(JSONArray jSONArray, CallbackContext callbackContext) { try { int i = jSONArray.getInt(0); if (i != -1) { JPushInterface.clearNotificationById(this.f0cordova.getActivity(), i); } else { callbackContext.error("error id"); } } catch (JSONException e) { e.printStackTrace(); callbackContext.error("error reading id json"); } } /* access modifiers changed from: package-private */ public void addLocalNotification(JSONArray jSONArray, CallbackContext callbackContext) throws JSONException { int i = jSONArray.getInt(0); String string = jSONArray.getString(1); String string2 = jSONArray.getString(2); int i2 = jSONArray.getInt(3); int i3 = jSONArray.getInt(4); String string3 = jSONArray.isNull(5) ? "" : jSONArray.getString(5); JSONObject jSONObject = new JSONObject(); if (!string3.isEmpty()) { jSONObject = new JSONObject(string3); } JPushLocalNotification jPushLocalNotification = new JPushLocalNotification(); jPushLocalNotification.setBuilderId((long) i); jPushLocalNotification.setContent(string); jPushLocalNotification.setTitle(string2); jPushLocalNotification.setNotificationId((long) i2); jPushLocalNotification.setBroadcastTime(System.currentTimeMillis() + ((long) i3)); jPushLocalNotification.setExtras(jSONObject.toString()); JPushInterface.addLocalNotification(this.f0cordova.getActivity(), jPushLocalNotification); } /* access modifiers changed from: package-private */ public void removeLocalNotification(JSONArray jSONArray, CallbackContext callbackContext) throws JSONException { JPushInterface.removeLocalNotification(this.f0cordova.getActivity(), (long) jSONArray.getInt(0)); } /* access modifiers changed from: package-private */ public void clearLocalNotifications(JSONArray jSONArray, CallbackContext callbackContext) { JPushInterface.clearLocalNotifications(this.f0cordova.getActivity()); } /* access modifiers changed from: package-private */ public void setSilenceTime(JSONArray jSONArray, CallbackContext callbackContext) { try { int i = jSONArray.getInt(0); int i2 = jSONArray.getInt(1); int i3 = jSONArray.getInt(2); int i4 = jSONArray.getInt(3); if (isValidHour(i)) { if (isValidMinute(i2)) { if (isValidHour(i3)) { if (isValidMinute(i4)) { JPushInterface.setSilenceTime(this.f0cordova.getActivity(), i, i2, i3, i4); return; } } callbackContext.error("结束时间数值错误"); return; } } callbackContext.error("开始时间数值错误"); } catch (JSONException e) { e.printStackTrace(); callbackContext.error("error: reading json data."); } } /* access modifiers changed from: package-private */ public void setGeofenceInterval(JSONArray jSONArray, CallbackContext callbackContext) throws JSONException { JPushInterface.setGeofenceInterval(this.f0cordova.getActivity(), jSONArray.getLong(0)); } /* access modifiers changed from: package-private */ public void setMaxGeofenceNumber(JSONArray jSONArray, CallbackContext callbackContext) throws JSONException { JPushInterface.setMaxGeofenceNumber(this.mContext, jSONArray.getInt(0)); } /* access modifiers changed from: package-private */ public void setBadgeNumber(JSONArray jSONArray, CallbackContext callbackContext) throws JSONException { JPushInterface.setBadgeNumber(this.mContext, jSONArray.getInt(0)); } /* access modifiers changed from: package-private */ public void requestPermission(JSONArray jSONArray, CallbackContext callbackContext) { JPushInterface.requestPermission(this.f0cordova.getActivity()); } private boolean hasPermission(String str) { Context applicationContext = this.f0cordova.getActivity().getApplicationContext(); if (Build.VERSION.SDK_INT >= 24) { return ((NotificationManager) applicationContext.getSystemService("notification")).areNotificationsEnabled(); } AppOpsManager appOpsManager = (AppOpsManager) applicationContext.getSystemService("appops"); ApplicationInfo applicationInfo = applicationContext.getApplicationInfo(); String packageName = applicationContext.getPackageName(); int i = applicationInfo.uid; try { Class<?> cls = Class.forName(AppOpsManager.class.getName()); if (Integer.parseInt(cls.getMethod("checkOpNoThrow", Integer.TYPE, Integer.TYPE, String.class).invoke(appOpsManager, Integer.valueOf(cls.getDeclaredField(str).getInt(Integer.class)), Integer.valueOf(i), packageName).toString()) == 0) { return true; } return false; } catch (InvocationTargetException e) { e.printStackTrace(); return false; } catch (IllegalAccessException e2) { e2.printStackTrace(); return false; } catch (NoSuchMethodException e3) { e3.printStackTrace(); return false; } catch (NoSuchFieldException e4) { e4.printStackTrace(); return false; } catch (ClassNotFoundException e5) { e5.printStackTrace(); return false; } } }