Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Commit

Permalink
fix: permission check via non-sdk19/4.4+
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-wicki committed Jan 14, 2016
1 parent 798836f commit 1557f73
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/android/com/adobe/phonegap/push/PermissionUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.adobe.phonegap.push;

import android.app.AppOpsManager;
import android.content.Context;
import android.content.pm.ApplicationInfo;

Expand All @@ -14,16 +13,16 @@ public class PermissionUtils {

public static boolean hasPermission(Context appContext, String appOpsServiceId) throws UnknownError {

AppOpsManager mAppOps = (AppOpsManager) appContext.getSystemService(Context.APP_OPS_SERVICE);
ApplicationInfo appInfo = appContext.getApplicationInfo();

String pkg = appContext.getPackageName();
int uid = appInfo.uid;
Class appOpsClass = null;
Object appOps = appContext.getSystemService("appops");

try {

appOpsClass = Class.forName(AppOpsManager.class.getName());
appOpsClass = Class.forName("android.app.AppOpsManager");

Method checkOpNoThrowMethod = appOpsClass.getMethod(
CHECK_OP_NO_THROW,
Expand All @@ -35,9 +34,9 @@ public static boolean hasPermission(Context appContext, String appOpsServiceId)
Field opValue = appOpsClass.getDeclaredField(appOpsServiceId);

int value = (int) opValue.getInt(Integer.class);
Object result = checkOpNoThrowMethod.invoke(mAppOps, value, uid, pkg);
Object result = checkOpNoThrowMethod.invoke(appOps, value, uid, pkg);

return Integer.parseInt(result.toString()) == AppOpsManager.MODE_ALLOWED; // type madness
return Integer.parseInt(result.toString()) == 0; // AppOpsManager.MODE_ALLOWED

} catch (ClassNotFoundException e) {
throw new UnknownError("class not found");
Expand Down

0 comments on commit 1557f73

Please sign in to comment.