summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api/system-current.txt1
-rw-r--r--core/java/android/content/pm/permission/IRuntimePermissionPresenter.aidl3
-rw-r--r--core/java/android/content/pm/permission/RuntimePermissionPresenter.java77
-rw-r--r--core/java/android/permissionpresenterservice/RuntimePermissionPresenterService.java27
4 files changed, 107 insertions, 1 deletions
diff --git a/api/system-current.txt b/api/system-current.txt
index b24064a57345..1f590dd5e6f0 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -33113,6 +33113,7 @@ package android.permissionpresenterservice {
method public final void attachBaseContext(android.content.Context);
method public final android.os.IBinder onBind(android.content.Intent);
method public abstract java.util.List<android.content.pm.permission.RuntimePermissionPresentationInfo> onGetAppPermissions(java.lang.String);
+ method public abstract java.util.List<android.content.pm.ApplicationInfo> onGetAppsUsingPermissions(boolean);
field public static final java.lang.String SERVICE_INTERFACE = "android.permissionpresenterservice.RuntimePermissionPresenterService";
}
diff --git a/core/java/android/content/pm/permission/IRuntimePermissionPresenter.aidl b/core/java/android/content/pm/permission/IRuntimePermissionPresenter.aidl
index 3c3b84d7b2a3..8766508a5c89 100644
--- a/core/java/android/content/pm/permission/IRuntimePermissionPresenter.aidl
+++ b/core/java/android/content/pm/permission/IRuntimePermissionPresenter.aidl
@@ -25,4 +25,5 @@ import android.os.RemoteCallback;
*/
oneway interface IRuntimePermissionPresenter {
void getAppPermissions(String packageName, in RemoteCallback callback);
-}
+ void getAppsUsingPermissions(boolean system, in RemoteCallback callback);
+} \ No newline at end of file
diff --git a/core/java/android/content/pm/permission/RuntimePermissionPresenter.java b/core/java/android/content/pm/permission/RuntimePermissionPresenter.java
index 6d55d2f7a860..2e39926422fe 100644
--- a/core/java/android/content/pm/permission/RuntimePermissionPresenter.java
+++ b/core/java/android/content/pm/permission/RuntimePermissionPresenter.java
@@ -72,6 +72,15 @@ public final class RuntimePermissionPresenter {
List<RuntimePermissionPresentationInfo> permissions) {
/* do nothing - stub */
}
+
+ /**
+ * The result for {@link #getAppsUsingPermissions(boolean, List)}.
+ * @param system Whether to return only the system apps or only the non-system ones.
+ * @param apps The apps using runtime permissions.
+ */
+ public void getAppsUsingPermissions(boolean system, @NonNull List<ApplicationInfo> apps) {
+ /* do nothing - stub */
+ }
}
private static final Object sLock = new Object();
@@ -118,6 +127,29 @@ public final class RuntimePermissionPresenter {
mRemoteService.processMessage(message);
}
+ /**
+ * Gets the system apps that use runtime permissions. System apps are ones
+ * that are considered system for presentation purposes instead of ones
+ * that are preinstalled on the system image. System apps are ones that
+ * are on the system image, haven't been updated (a.k.a factory apps)
+ * that do not have a launcher icon.
+ *
+ * @param system If true only system apps are returned otherwise only
+ * non-system ones are returned.
+ * @param callback Callback to receive the result.
+ * @param handler Handler on which to invoke the callback.
+ */
+ public void getAppsUsingPermissions(boolean system, @NonNull OnResultCallback callback,
+ @Nullable Handler handler) {
+ SomeArgs args = SomeArgs.obtain();
+ args.arg1 = callback;
+ args.arg2 = handler;
+ args.argi1 = system ? 1 : 0;
+ Message message = mRemoteService.obtainMessage(
+ RemoteService.MSG_GET_APPS_USING_PERMISSIONS, args);
+ mRemoteService.processMessage(message);
+ }
+
private static final class RemoteService
extends Handler implements ServiceConnection {
private static final long UNBIND_TIMEOUT_MILLIS = 10000;
@@ -222,6 +254,51 @@ public final class RuntimePermissionPresenter {
scheduleUnbind();
} break;
+ case MSG_GET_APPS_USING_PERMISSIONS: {
+ SomeArgs args = (SomeArgs) msg.obj;
+ final OnResultCallback callback = (OnResultCallback) args.arg1;
+ final Handler handler = (Handler) args.arg2;
+ final boolean system = args.argi1 == 1;
+ args.recycle();
+ final IRuntimePermissionPresenter remoteInstance;
+ synchronized (mLock) {
+ remoteInstance = mRemoteInstance;
+ }
+ if (remoteInstance == null) {
+ return;
+ }
+ try {
+ remoteInstance.getAppsUsingPermissions(system, new RemoteCallback(
+ new RemoteCallback.OnResultListener() {
+ @Override
+ public void onResult(Bundle result) {
+ final List<ApplicationInfo> reportedApps;
+ List<ApplicationInfo> apps = null;
+ if (result != null) {
+ apps = result.getParcelableArrayList(KEY_RESULT);
+ }
+ if (apps == null) {
+ apps = Collections.emptyList();
+ }
+ reportedApps = apps;
+ if (handler != null) {
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ callback.getAppsUsingPermissions(system, reportedApps);
+ }
+ });
+ } else {
+ callback.getAppsUsingPermissions(system, reportedApps);
+ }
+ }
+ }, this));
+ } catch (RemoteException re) {
+ Log.e(TAG, "Error getting apps using permissions", re);
+ }
+ scheduleUnbind();
+ } break;
+
case MSG_UNBIND: {
synchronized (mLock) {
if (mBound) {
diff --git a/core/java/android/permissionpresenterservice/RuntimePermissionPresenterService.java b/core/java/android/permissionpresenterservice/RuntimePermissionPresenterService.java
index 344d947a3ad3..405be1a2520c 100644
--- a/core/java/android/permissionpresenterservice/RuntimePermissionPresenterService.java
+++ b/core/java/android/permissionpresenterservice/RuntimePermissionPresenterService.java
@@ -72,6 +72,14 @@ public abstract class RuntimePermissionPresenterService extends Service {
*/
public abstract List<RuntimePermissionPresentationInfo> onGetAppPermissions(String packageName);
+ /**
+ * Gets the apps that use runtime permissions.
+ *
+ * @param system Whether to return only the system apps or only the non-system ones.
+ * @return The app list.
+ */
+ public abstract List<ApplicationInfo> onGetAppsUsingPermissions(boolean system);
+
@Override
public final IBinder onBind(Intent intent) {
return new IRuntimePermissionPresenter.Stub() {
@@ -83,6 +91,12 @@ public abstract class RuntimePermissionPresenterService extends Service {
mHandler.obtainMessage(MyHandler.MSG_GET_APP_PERMISSIONS,
args).sendToTarget();
}
+
+ @Override
+ public void getAppsUsingPermissions(boolean system, RemoteCallback callback) {
+ mHandler.obtainMessage(MyHandler.MSG_GET_APPS_USING_PERMISSIONS,
+ system ? 1 : 0, 0, callback).sendToTarget();
+ }
};
}
@@ -113,6 +127,19 @@ public abstract class RuntimePermissionPresenterService extends Service {
callback.sendResult(null);
}
} break;
+
+ case MSG_GET_APPS_USING_PERMISSIONS: {
+ RemoteCallback callback = (RemoteCallback) msg.obj;
+ final boolean system = msg.arg1 == 1;
+ List<ApplicationInfo> apps = onGetAppsUsingPermissions(system);
+ if (apps != null && !apps.isEmpty()) {
+ Bundle result = new Bundle();
+ result.putParcelableList(RuntimePermissionPresenter.KEY_RESULT, apps);
+ callback.sendResult(result);
+ } else {
+ callback.sendResult(null);
+ }
+ } break;
}
}
}