Merge changes Id642f836,I5550b1ca
* changes: Move most of AppOpsService implementation behind an interface Copy AppOpsService into AppOpsCheckingServiceImpl
This commit is contained in:
committed by
Android (Google) Code Review
commit
894ef374e5
@@ -20,7 +20,7 @@ import static android.app.AppOpsManager.OP_NONE;
|
||||
import static android.app.AppOpsManager.WATCH_FOREGROUND_CHANGES;
|
||||
import static android.app.AppOpsManager.opRestrictsRead;
|
||||
|
||||
import static com.android.server.appop.AppOpsService.ModeCallback.ALL_OPS;
|
||||
import static com.android.server.appop.AppOpsServiceImpl.ModeCallback.ALL_OPS;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.NonNull;
|
||||
@@ -56,7 +56,7 @@ import java.util.Objects;
|
||||
* Legacy implementation for App-ops service's app-op mode (uid and package) storage and access.
|
||||
* In the future this class will also include mode callbacks and op restrictions.
|
||||
*/
|
||||
public class LegacyAppOpsServiceInterfaceImpl implements AppOpsServiceInterface {
|
||||
public class AppOpsCheckingServiceImpl implements AppOpsCheckingServiceInterface {
|
||||
|
||||
static final String TAG = "LegacyAppOpsServiceInterfaceImpl";
|
||||
|
||||
@@ -84,9 +84,9 @@ public class LegacyAppOpsServiceInterfaceImpl implements AppOpsServiceInterface
|
||||
private static final int UID_ANY = -2;
|
||||
|
||||
|
||||
LegacyAppOpsServiceInterfaceImpl(PersistenceScheduler persistenceScheduler,
|
||||
@NonNull Object lock, Handler handler, Context context,
|
||||
SparseArray<int[]> switchedOps) {
|
||||
AppOpsCheckingServiceImpl(PersistenceScheduler persistenceScheduler,
|
||||
@NonNull Object lock, Handler handler, Context context,
|
||||
SparseArray<int[]> switchedOps) {
|
||||
this.mPersistenceScheduler = persistenceScheduler;
|
||||
this.mLock = lock;
|
||||
this.mHandler = handler;
|
||||
@@ -456,7 +456,7 @@ public class LegacyAppOpsServiceInterfaceImpl implements AppOpsServiceInterface
|
||||
final ArraySet<String> reportedPackageNames = callbackSpecs.valueAt(i);
|
||||
if (reportedPackageNames == null) {
|
||||
mHandler.sendMessage(PooledLambda.obtainMessage(
|
||||
LegacyAppOpsServiceInterfaceImpl::notifyOpChanged,
|
||||
AppOpsCheckingServiceImpl::notifyOpChanged,
|
||||
this, callback, code, uid, (String) null));
|
||||
|
||||
} else {
|
||||
@@ -464,7 +464,7 @@ public class LegacyAppOpsServiceInterfaceImpl implements AppOpsServiceInterface
|
||||
for (int j = 0; j < reportedPackageCount; j++) {
|
||||
final String reportedPackageName = reportedPackageNames.valueAt(j);
|
||||
mHandler.sendMessage(PooledLambda.obtainMessage(
|
||||
LegacyAppOpsServiceInterfaceImpl::notifyOpChanged,
|
||||
AppOpsCheckingServiceImpl::notifyOpChanged,
|
||||
this, callback, code, uid, reportedPackageName));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.server.appop;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.app.AppOpsManager.Mode;
|
||||
import android.util.ArraySet;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* Interface for accessing and modifying modes for app-ops i.e. package and uid modes.
|
||||
* This interface also includes functions for added and removing op mode watchers.
|
||||
* In the future this interface will also include op restrictions.
|
||||
*/
|
||||
public interface AppOpsCheckingServiceInterface {
|
||||
/**
|
||||
* Returns a copy of non-default app-ops with op as keys and their modes as values for a uid.
|
||||
* Returns an empty SparseIntArray if nothing is set.
|
||||
* @param uid for which we need the app-ops and their modes.
|
||||
*/
|
||||
SparseIntArray getNonDefaultUidModes(int uid);
|
||||
|
||||
/**
|
||||
* Returns the app-op mode for a particular app-op of a uid.
|
||||
* Returns default op mode if the op mode for particular uid and op is not set.
|
||||
* @param uid user id for which we need the mode.
|
||||
* @param op app-op for which we need the mode.
|
||||
* @return mode of the app-op.
|
||||
*/
|
||||
int getUidMode(int uid, int op);
|
||||
|
||||
/**
|
||||
* Set the app-op mode for a particular uid and op.
|
||||
* The mode is not set if the mode is the same as the default mode for the op.
|
||||
* @param uid user id for which we want to set the mode.
|
||||
* @param op app-op for which we want to set the mode.
|
||||
* @param mode mode for the app-op.
|
||||
* @return true if op mode is changed.
|
||||
*/
|
||||
boolean setUidMode(int uid, int op, @Mode int mode);
|
||||
|
||||
/**
|
||||
* Gets the app-op mode for a particular package.
|
||||
* Returns default op mode if the op mode for the particular package is not set.
|
||||
* @param packageName package name for which we need the op mode.
|
||||
* @param op app-op for which we need the mode.
|
||||
* @param userId user id associated with the package.
|
||||
* @return the mode of the app-op.
|
||||
*/
|
||||
int getPackageMode(@NonNull String packageName, int op, @UserIdInt int userId);
|
||||
|
||||
/**
|
||||
* Sets the app-op mode for a particular package.
|
||||
* @param packageName package name for which we need to set the op mode.
|
||||
* @param op app-op for which we need to set the mode.
|
||||
* @param mode the mode of the app-op.
|
||||
* @param userId user id associated with the package.
|
||||
*
|
||||
*/
|
||||
void setPackageMode(@NonNull String packageName, int op, @Mode int mode, @UserIdInt int userId);
|
||||
|
||||
/**
|
||||
* Stop tracking any app-op modes for a package.
|
||||
* @param packageName Name of the package for which we want to remove all mode tracking.
|
||||
* @param userId user id associated with the package.
|
||||
*/
|
||||
boolean removePackage(@NonNull String packageName, @UserIdInt int userId);
|
||||
|
||||
/**
|
||||
* Stop tracking any app-op modes for this uid.
|
||||
* @param uid user id for which we want to remove all tracking.
|
||||
*/
|
||||
void removeUid(int uid);
|
||||
|
||||
/**
|
||||
* Returns true if all uid modes for this uid are
|
||||
* in default state.
|
||||
* @param uid user id
|
||||
*/
|
||||
boolean areUidModesDefault(int uid);
|
||||
|
||||
/**
|
||||
* Returns true if all package modes for this package name are
|
||||
* in default state.
|
||||
* @param packageName package name.
|
||||
* @param userId user id associated with the package.
|
||||
*/
|
||||
boolean arePackageModesDefault(String packageName, @UserIdInt int userId);
|
||||
|
||||
/**
|
||||
* Stop tracking app-op modes for all uid and packages.
|
||||
*/
|
||||
void clearAllModes();
|
||||
|
||||
/**
|
||||
* Registers changedListener to listen to op's mode change.
|
||||
* @param changedListener the listener that must be trigger on the op's mode change.
|
||||
* @param op op representing the app-op whose mode change needs to be listened to.
|
||||
*/
|
||||
void startWatchingOpModeChanged(@NonNull OnOpModeChangedListener changedListener, int op);
|
||||
|
||||
/**
|
||||
* Registers changedListener to listen to package's app-op's mode change.
|
||||
* @param changedListener the listener that must be trigger on the mode change.
|
||||
* @param packageName of the package whose app-op's mode change needs to be listened to.
|
||||
*/
|
||||
void startWatchingPackageModeChanged(@NonNull OnOpModeChangedListener changedListener,
|
||||
@NonNull String packageName);
|
||||
|
||||
/**
|
||||
* Stop the changedListener from triggering on any mode change.
|
||||
* @param changedListener the listener that needs to be removed.
|
||||
*/
|
||||
void removeListener(@NonNull OnOpModeChangedListener changedListener);
|
||||
|
||||
/**
|
||||
* Temporary API which will be removed once we can safely untangle the methods that use this.
|
||||
* Returns a set of OnOpModeChangedListener that are listening for op's mode changes.
|
||||
* @param op app-op whose mode change is being listened to.
|
||||
*/
|
||||
ArraySet<OnOpModeChangedListener> getOpModeChangedListeners(int op);
|
||||
|
||||
/**
|
||||
* Temporary API which will be removed once we can safely untangle the methods that use this.
|
||||
* Returns a set of OnOpModeChangedListener that are listening for package's op's mode changes.
|
||||
* @param packageName of package whose app-op's mode change is being listened to.
|
||||
*/
|
||||
ArraySet<OnOpModeChangedListener> getPackageModeChangedListeners(@NonNull String packageName);
|
||||
|
||||
/**
|
||||
* Temporary API which will be removed once we can safely untangle the methods that use this.
|
||||
* Notify that the app-op's mode is changed by triggering the change listener.
|
||||
* @param op App-op whose mode has changed
|
||||
* @param uid user id associated with the app-op (or, if UID_ANY, notifies all users)
|
||||
*/
|
||||
void notifyWatchersOfChange(int op, int uid);
|
||||
|
||||
/**
|
||||
* Temporary API which will be removed once we can safely untangle the methods that use this.
|
||||
* Notify that the app-op's mode is changed by triggering the change listener.
|
||||
* @param changedListener the change listener.
|
||||
* @param op App-op whose mode has changed
|
||||
* @param uid user id associated with the app-op
|
||||
* @param packageName package name that is associated with the app-op
|
||||
*/
|
||||
void notifyOpChanged(@NonNull OnOpModeChangedListener changedListener, int op, int uid,
|
||||
@Nullable String packageName);
|
||||
|
||||
/**
|
||||
* Temporary API which will be removed once we can safely untangle the methods that use this.
|
||||
* Notify that the app-op's mode is changed to all packages associated with the uid by
|
||||
* triggering the appropriate change listener.
|
||||
* @param op App-op whose mode has changed
|
||||
* @param uid user id associated with the app-op
|
||||
* @param onlyForeground true if only watchers that
|
||||
* @param callbackToIgnore callback that should be ignored.
|
||||
*/
|
||||
void notifyOpChangedForAllPkgsInUid(int op, int uid, boolean onlyForeground,
|
||||
@Nullable OnOpModeChangedListener callbackToIgnore);
|
||||
|
||||
/**
|
||||
* TODO: Move hasForegroundWatchers and foregroundOps into this.
|
||||
* Go over the list of app-ops for the uid and mark app-ops with MODE_FOREGROUND in
|
||||
* foregroundOps.
|
||||
* @param uid for which the app-op's mode needs to be marked.
|
||||
* @param foregroundOps boolean array where app-ops that have MODE_FOREGROUND are marked true.
|
||||
* @return foregroundOps.
|
||||
*/
|
||||
SparseBooleanArray evalForegroundUidOps(int uid, SparseBooleanArray foregroundOps);
|
||||
|
||||
/**
|
||||
* Go over the list of app-ops for the package name and mark app-ops with MODE_FOREGROUND in
|
||||
* foregroundOps.
|
||||
* @param packageName for which the app-op's mode needs to be marked.
|
||||
* @param foregroundOps boolean array where app-ops that have MODE_FOREGROUND are marked true.
|
||||
* @param userId user id associated with the package.
|
||||
* @return foregroundOps.
|
||||
*/
|
||||
SparseBooleanArray evalForegroundPackageOps(String packageName,
|
||||
SparseBooleanArray foregroundOps, @UserIdInt int userId);
|
||||
|
||||
/**
|
||||
* Dump op mode and package mode listeners and their details.
|
||||
* @param dumpOp if -1 then op mode listeners for all app-ops are dumped. If it's set to an
|
||||
* app-op, only the watchers for that app-op are dumped.
|
||||
* @param dumpUid uid for which we want to dump op mode watchers.
|
||||
* @param dumpPackage if not null and if dumpOp is -1, dumps watchers for the package name.
|
||||
* @param printWriter writer to dump to.
|
||||
*/
|
||||
boolean dumpListeners(int dumpOp, int dumpUid, String dumpPackage, PrintWriter printWriter);
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public class AppOpsRestrictionsImpl implements AppOpsRestrictions {
|
||||
|
||||
private Context mContext;
|
||||
private Handler mHandler;
|
||||
private AppOpsServiceInterface mAppOpsServiceInterface;
|
||||
private AppOpsCheckingServiceInterface mAppOpsServiceInterface;
|
||||
|
||||
// Map from (Object token) to (int code) to (boolean restricted)
|
||||
private final ArrayMap<Object, SparseBooleanArray> mGlobalRestrictions = new ArrayMap<>();
|
||||
@@ -56,7 +56,7 @@ public class AppOpsRestrictionsImpl implements AppOpsRestrictions {
|
||||
mUserRestrictionExcludedPackageTags = new ArrayMap<>();
|
||||
|
||||
public AppOpsRestrictionsImpl(Context context, Handler handler,
|
||||
AppOpsServiceInterface appOpsServiceInterface) {
|
||||
AppOpsCheckingServiceInterface appOpsServiceInterface) {
|
||||
mContext = context;
|
||||
mHandler = handler;
|
||||
mAppOpsServiceInterface = appOpsServiceInterface;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
4679
services/core/java/com/android/server/appop/AppOpsServiceImpl.java
Normal file
4679
services/core/java/com/android/server/appop/AppOpsServiceImpl.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -13,197 +13,482 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.server.appop;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.app.AppOpsManager.Mode;
|
||||
import android.util.ArraySet;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AppOpsManager;
|
||||
import android.content.AttributionSource;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.PackageTagsList;
|
||||
import android.os.RemoteCallback;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.util.SparseArray;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import com.android.internal.app.IAppOpsActiveCallback;
|
||||
import com.android.internal.app.IAppOpsCallback;
|
||||
import com.android.internal.app.IAppOpsNotedCallback;
|
||||
import com.android.internal.app.IAppOpsStartedCallback;
|
||||
|
||||
import dalvik.annotation.optimization.NeverCompile;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Interface for accessing and modifying modes for app-ops i.e. package and uid modes.
|
||||
* This interface also includes functions for added and removing op mode watchers.
|
||||
* In the future this interface will also include op restrictions.
|
||||
*
|
||||
*/
|
||||
public interface AppOpsServiceInterface {
|
||||
/**
|
||||
* Returns a copy of non-default app-ops with op as keys and their modes as values for a uid.
|
||||
* Returns an empty SparseIntArray if nothing is set.
|
||||
* @param uid for which we need the app-ops and their modes.
|
||||
*/
|
||||
SparseIntArray getNonDefaultUidModes(int uid);
|
||||
public interface AppOpsServiceInterface extends PersistenceScheduler {
|
||||
|
||||
/**
|
||||
* Returns the app-op mode for a particular app-op of a uid.
|
||||
* Returns default op mode if the op mode for particular uid and op is not set.
|
||||
* @param uid user id for which we need the mode.
|
||||
* @param op app-op for which we need the mode.
|
||||
* @return mode of the app-op.
|
||||
*/
|
||||
int getUidMode(int uid, int op);
|
||||
|
||||
/**
|
||||
* Set the app-op mode for a particular uid and op.
|
||||
* The mode is not set if the mode is the same as the default mode for the op.
|
||||
* @param uid user id for which we want to set the mode.
|
||||
* @param op app-op for which we want to set the mode.
|
||||
* @param mode mode for the app-op.
|
||||
* @return true if op mode is changed.
|
||||
*/
|
||||
boolean setUidMode(int uid, int op, @Mode int mode);
|
||||
|
||||
/**
|
||||
* Gets the app-op mode for a particular package.
|
||||
* Returns default op mode if the op mode for the particular package is not set.
|
||||
* @param packageName package name for which we need the op mode.
|
||||
* @param op app-op for which we need the mode.
|
||||
* @param userId user id associated with the package.
|
||||
* @return the mode of the app-op.
|
||||
*/
|
||||
int getPackageMode(@NonNull String packageName, int op, @UserIdInt int userId);
|
||||
|
||||
/**
|
||||
* Sets the app-op mode for a particular package.
|
||||
* @param packageName package name for which we need to set the op mode.
|
||||
* @param op app-op for which we need to set the mode.
|
||||
* @param mode the mode of the app-op.
|
||||
* @param userId user id associated with the package.
|
||||
*
|
||||
*/
|
||||
void setPackageMode(@NonNull String packageName, int op, @Mode int mode, @UserIdInt int userId);
|
||||
void systemReady();
|
||||
|
||||
/**
|
||||
* Stop tracking any app-op modes for a package.
|
||||
* @param packageName Name of the package for which we want to remove all mode tracking.
|
||||
* @param userId user id associated with the package.
|
||||
*
|
||||
*/
|
||||
boolean removePackage(@NonNull String packageName, @UserIdInt int userId);
|
||||
void shutdown();
|
||||
|
||||
/**
|
||||
* Stop tracking any app-op modes for this uid.
|
||||
* @param uid user id for which we want to remove all tracking.
|
||||
*
|
||||
* @param uid
|
||||
* @param packageName
|
||||
*/
|
||||
void removeUid(int uid);
|
||||
void verifyPackage(int uid, String packageName);
|
||||
|
||||
/**
|
||||
* Returns true if all uid modes for this uid are
|
||||
* in default state.
|
||||
* @param uid user id
|
||||
*
|
||||
* @param op
|
||||
* @param packageName
|
||||
* @param flags
|
||||
* @param callback
|
||||
*/
|
||||
boolean areUidModesDefault(int uid);
|
||||
void startWatchingModeWithFlags(int op, String packageName, int flags,
|
||||
IAppOpsCallback callback);
|
||||
|
||||
/**
|
||||
* Returns true if all package modes for this package name are
|
||||
* in default state.
|
||||
* @param packageName package name.
|
||||
* @param userId user id associated with the package.
|
||||
*
|
||||
* @param callback
|
||||
*/
|
||||
boolean arePackageModesDefault(String packageName, @UserIdInt int userId);
|
||||
void stopWatchingMode(IAppOpsCallback callback);
|
||||
|
||||
/**
|
||||
* Stop tracking app-op modes for all uid and packages.
|
||||
*
|
||||
* @param ops
|
||||
* @param callback
|
||||
*/
|
||||
void clearAllModes();
|
||||
void startWatchingActive(int[] ops, IAppOpsActiveCallback callback);
|
||||
|
||||
/**
|
||||
* Registers changedListener to listen to op's mode change.
|
||||
* @param changedListener the listener that must be trigger on the op's mode change.
|
||||
* @param op op representing the app-op whose mode change needs to be listened to.
|
||||
*
|
||||
* @param callback
|
||||
*/
|
||||
void startWatchingOpModeChanged(@NonNull OnOpModeChangedListener changedListener, int op);
|
||||
void stopWatchingActive(IAppOpsActiveCallback callback);
|
||||
|
||||
/**
|
||||
* Registers changedListener to listen to package's app-op's mode change.
|
||||
* @param changedListener the listener that must be trigger on the mode change.
|
||||
* @param packageName of the package whose app-op's mode change needs to be listened to.
|
||||
*
|
||||
* @param ops
|
||||
* @param callback
|
||||
*/
|
||||
void startWatchingPackageModeChanged(@NonNull OnOpModeChangedListener changedListener,
|
||||
@NonNull String packageName);
|
||||
void startWatchingStarted(int[] ops, @NonNull IAppOpsStartedCallback callback);
|
||||
|
||||
/**
|
||||
* Stop the changedListener from triggering on any mode change.
|
||||
* @param changedListener the listener that needs to be removed.
|
||||
*
|
||||
* @param callback
|
||||
*/
|
||||
void removeListener(@NonNull OnOpModeChangedListener changedListener);
|
||||
void stopWatchingStarted(IAppOpsStartedCallback callback);
|
||||
|
||||
/**
|
||||
* Temporary API which will be removed once we can safely untangle the methods that use this.
|
||||
* Returns a set of OnOpModeChangedListener that are listening for op's mode changes.
|
||||
* @param op app-op whose mode change is being listened to.
|
||||
*
|
||||
* @param ops
|
||||
* @param callback
|
||||
*/
|
||||
ArraySet<OnOpModeChangedListener> getOpModeChangedListeners(int op);
|
||||
void startWatchingNoted(@NonNull int[] ops, @NonNull IAppOpsNotedCallback callback);
|
||||
|
||||
/**
|
||||
* Temporary API which will be removed once we can safely untangle the methods that use this.
|
||||
* Returns a set of OnOpModeChangedListener that are listening for package's op's mode changes.
|
||||
* @param packageName of package whose app-op's mode change is being listened to.
|
||||
*
|
||||
* @param callback
|
||||
*/
|
||||
ArraySet<OnOpModeChangedListener> getPackageModeChangedListeners(@NonNull String packageName);
|
||||
void stopWatchingNoted(IAppOpsNotedCallback callback);
|
||||
|
||||
/**
|
||||
* Temporary API which will be removed once we can safely untangle the methods that use this.
|
||||
* Notify that the app-op's mode is changed by triggering the change listener.
|
||||
* @param op App-op whose mode has changed
|
||||
* @param uid user id associated with the app-op (or, if UID_ANY, notifies all users)
|
||||
* @param clientId
|
||||
* @param code
|
||||
* @param uid
|
||||
* @param packageName
|
||||
* @param attributionTag
|
||||
* @param startIfModeDefault
|
||||
* @param message
|
||||
* @param attributionFlags
|
||||
* @param attributionChainId
|
||||
* @return
|
||||
*/
|
||||
void notifyWatchersOfChange(int op, int uid);
|
||||
int startOperation(@NonNull IBinder clientId, int code, int uid,
|
||||
@Nullable String packageName, @Nullable String attributionTag,
|
||||
boolean startIfModeDefault, @NonNull String message,
|
||||
@AppOpsManager.AttributionFlags int attributionFlags,
|
||||
int attributionChainId);
|
||||
|
||||
|
||||
int startOperationUnchecked(IBinder clientId, int code, int uid, @NonNull String packageName,
|
||||
@Nullable String attributionTag, int proxyUid, String proxyPackageName,
|
||||
@Nullable String proxyAttributionTag, @AppOpsManager.OpFlags int flags,
|
||||
boolean startIfModeDefault, @AppOpsManager.AttributionFlags int attributionFlags,
|
||||
int attributionChainId, boolean dryRun);
|
||||
|
||||
/**
|
||||
* Temporary API which will be removed once we can safely untangle the methods that use this.
|
||||
* Notify that the app-op's mode is changed by triggering the change listener.
|
||||
* @param changedListener the change listener.
|
||||
* @param op App-op whose mode has changed
|
||||
* @param uid user id associated with the app-op
|
||||
* @param packageName package name that is associated with the app-op
|
||||
*
|
||||
* @param clientId
|
||||
* @param code
|
||||
* @param uid
|
||||
* @param packageName
|
||||
* @param attributionTag
|
||||
*/
|
||||
void notifyOpChanged(@NonNull OnOpModeChangedListener changedListener, int op, int uid,
|
||||
@Nullable String packageName);
|
||||
void finishOperation(IBinder clientId, int code, int uid, String packageName,
|
||||
String attributionTag);
|
||||
|
||||
/**
|
||||
* Temporary API which will be removed once we can safely untangle the methods that use this.
|
||||
* Notify that the app-op's mode is changed to all packages associated with the uid by
|
||||
* triggering the appropriate change listener.
|
||||
* @param op App-op whose mode has changed
|
||||
* @param uid user id associated with the app-op
|
||||
* @param onlyForeground true if only watchers that
|
||||
* @param callbackToIgnore callback that should be ignored.
|
||||
*
|
||||
* @param clientId
|
||||
* @param code
|
||||
* @param uid
|
||||
* @param packageName
|
||||
* @param attributionTag
|
||||
*/
|
||||
void notifyOpChangedForAllPkgsInUid(int op, int uid, boolean onlyForeground,
|
||||
@Nullable OnOpModeChangedListener callbackToIgnore);
|
||||
void finishOperationUnchecked(IBinder clientId, int code, int uid, String packageName,
|
||||
String attributionTag);
|
||||
|
||||
/**
|
||||
* TODO: Move hasForegroundWatchers and foregroundOps into this.
|
||||
* Go over the list of app-ops for the uid and mark app-ops with MODE_FOREGROUND in
|
||||
* foregroundOps.
|
||||
* @param uid for which the app-op's mode needs to be marked.
|
||||
* @param foregroundOps boolean array where app-ops that have MODE_FOREGROUND are marked true.
|
||||
* @return foregroundOps.
|
||||
*
|
||||
* @param uidPackageNames
|
||||
* @param visible
|
||||
*/
|
||||
SparseBooleanArray evalForegroundUidOps(int uid, SparseBooleanArray foregroundOps);
|
||||
void updateAppWidgetVisibility(SparseArray<String> uidPackageNames, boolean visible);
|
||||
|
||||
/**
|
||||
* Go over the list of app-ops for the package name and mark app-ops with MODE_FOREGROUND in
|
||||
* foregroundOps.
|
||||
* @param packageName for which the app-op's mode needs to be marked.
|
||||
* @param foregroundOps boolean array where app-ops that have MODE_FOREGROUND are marked true.
|
||||
* @param userId user id associated with the package.
|
||||
* @return foregroundOps.
|
||||
*
|
||||
*/
|
||||
SparseBooleanArray evalForegroundPackageOps(String packageName,
|
||||
SparseBooleanArray foregroundOps, @UserIdInt int userId);
|
||||
void readState();
|
||||
|
||||
/**
|
||||
* Dump op mode and package mode listeners and their details.
|
||||
* @param dumpOp if -1 then op mode listeners for all app-ops are dumped. If it's set to an
|
||||
* app-op, only the watchers for that app-op are dumped.
|
||||
* @param dumpUid uid for which we want to dump op mode watchers.
|
||||
* @param dumpPackage if not null and if dumpOp is -1, dumps watchers for the package name.
|
||||
* @param printWriter writer to dump to.
|
||||
*
|
||||
*/
|
||||
boolean dumpListeners(int dumpOp, int dumpUid, String dumpPackage, PrintWriter printWriter);
|
||||
void writeState();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uid
|
||||
* @param packageName
|
||||
*/
|
||||
void packageRemoved(int uid, String packageName);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uid
|
||||
*/
|
||||
void uidRemoved(int uid);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uid
|
||||
* @param procState
|
||||
* @param capability
|
||||
*/
|
||||
void updateUidProcState(int uid, int procState,
|
||||
@ActivityManager.ProcessCapability int capability);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ops
|
||||
* @return
|
||||
*/
|
||||
List<AppOpsManager.PackageOps> getPackagesForOps(int[] ops);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uid
|
||||
* @param packageName
|
||||
* @param ops
|
||||
* @return
|
||||
*/
|
||||
List<AppOpsManager.PackageOps> getOpsForPackage(int uid, String packageName,
|
||||
int[] ops);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uid
|
||||
* @param packageName
|
||||
* @param attributionTag
|
||||
* @param opNames
|
||||
* @param dataType
|
||||
* @param filter
|
||||
* @param beginTimeMillis
|
||||
* @param endTimeMillis
|
||||
* @param flags
|
||||
* @param callback
|
||||
*/
|
||||
void getHistoricalOps(int uid, String packageName, String attributionTag,
|
||||
List<String> opNames, int dataType, int filter, long beginTimeMillis,
|
||||
long endTimeMillis, int flags, RemoteCallback callback);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uid
|
||||
* @param packageName
|
||||
* @param attributionTag
|
||||
* @param opNames
|
||||
* @param dataType
|
||||
* @param filter
|
||||
* @param beginTimeMillis
|
||||
* @param endTimeMillis
|
||||
* @param flags
|
||||
* @param callback
|
||||
*/
|
||||
void getHistoricalOpsFromDiskRaw(int uid, String packageName, String attributionTag,
|
||||
List<String> opNames, int dataType, int filter, long beginTimeMillis,
|
||||
long endTimeMillis, int flags, RemoteCallback callback);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void reloadNonHistoricalState();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uid
|
||||
* @param ops
|
||||
* @return
|
||||
*/
|
||||
List<AppOpsManager.PackageOps> getUidOps(int uid, int[] ops);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param owners
|
||||
*/
|
||||
void setDeviceAndProfileOwners(SparseIntArray owners);
|
||||
|
||||
// used in audio restriction calls, might just copy the logic to avoid having this call.
|
||||
/**
|
||||
*
|
||||
* @param callingPid
|
||||
* @param callingUid
|
||||
* @param targetUid
|
||||
*/
|
||||
void enforceManageAppOpsModes(int callingPid, int callingUid, int targetUid);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param code
|
||||
* @param uid
|
||||
* @param mode
|
||||
* @param permissionPolicyCallback
|
||||
*/
|
||||
void setUidMode(int code, int uid, int mode,
|
||||
@Nullable IAppOpsCallback permissionPolicyCallback);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param code
|
||||
* @param uid
|
||||
* @param packageName
|
||||
* @param mode
|
||||
* @param permissionPolicyCallback
|
||||
*/
|
||||
void setMode(int code, int uid, @NonNull String packageName, int mode,
|
||||
@Nullable IAppOpsCallback permissionPolicyCallback);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param reqUserId
|
||||
* @param reqPackageName
|
||||
*/
|
||||
void resetAllModes(int reqUserId, String reqPackageName);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param code
|
||||
* @param uid
|
||||
* @param packageName
|
||||
* @param attributionTag
|
||||
* @param raw
|
||||
* @return
|
||||
*/
|
||||
int checkOperation(int code, int uid, String packageName,
|
||||
@Nullable String attributionTag, boolean raw);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uid
|
||||
* @param packageName
|
||||
* @return
|
||||
*/
|
||||
int checkPackage(int uid, String packageName);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param code
|
||||
* @param uid
|
||||
* @param packageName
|
||||
* @param attributionTag
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
int noteOperation(int code, int uid, @Nullable String packageName,
|
||||
@Nullable String attributionTag, @Nullable String message);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param code
|
||||
* @param uid
|
||||
* @param packageName
|
||||
* @param attributionTag
|
||||
* @param proxyUid
|
||||
* @param proxyPackageName
|
||||
* @param proxyAttributionTag
|
||||
* @param flags
|
||||
* @return
|
||||
*/
|
||||
@AppOpsManager.Mode
|
||||
int noteOperationUnchecked(int code, int uid, @NonNull String packageName,
|
||||
@Nullable String attributionTag, int proxyUid, String proxyPackageName,
|
||||
@Nullable String proxyAttributionTag, @AppOpsManager.OpFlags int flags);
|
||||
|
||||
boolean isAttributionTagValid(int uid, @NonNull String packageName,
|
||||
@Nullable String attributionTag, @Nullable String proxyPackageName);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param fd
|
||||
* @param pw
|
||||
* @param args
|
||||
*/
|
||||
@NeverCompile
|
||||
// Avoid size overhead of debugging code.
|
||||
void dump(FileDescriptor fd, PrintWriter pw, String[] args);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param restrictions
|
||||
* @param token
|
||||
* @param userHandle
|
||||
*/
|
||||
void setUserRestrictions(Bundle restrictions, IBinder token, int userHandle);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param code
|
||||
* @param restricted
|
||||
* @param token
|
||||
* @param userHandle
|
||||
* @param excludedPackageTags
|
||||
*/
|
||||
void setUserRestriction(int code, boolean restricted, IBinder token, int userHandle,
|
||||
PackageTagsList excludedPackageTags);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param code
|
||||
* @param restricted
|
||||
* @param token
|
||||
*/
|
||||
void setGlobalRestriction(int code, boolean restricted, IBinder token);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param code
|
||||
* @param user
|
||||
* @param pkg
|
||||
* @param attributionTag
|
||||
* @return
|
||||
*/
|
||||
int getOpRestrictionCount(int code, UserHandle user, String pkg,
|
||||
String attributionTag);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param code
|
||||
* @param uid
|
||||
*/
|
||||
// added to interface for audio restriction stuff
|
||||
void notifyWatchersOfChange(int code, int uid);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userHandle
|
||||
* @throws RemoteException
|
||||
*/
|
||||
void removeUser(int userHandle) throws RemoteException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param code
|
||||
* @param uid
|
||||
* @param packageName
|
||||
* @return
|
||||
*/
|
||||
boolean isOperationActive(int code, int uid, String packageName);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param op
|
||||
* @param proxyPackageName
|
||||
* @param proxyAttributionTag
|
||||
* @param proxiedUid
|
||||
* @param proxiedPackageName
|
||||
* @return
|
||||
*/
|
||||
// TODO this one might not need to be in the interface
|
||||
boolean isProxying(int op, @NonNull String proxyPackageName,
|
||||
@NonNull String proxyAttributionTag, int proxiedUid,
|
||||
@NonNull String proxiedPackageName);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param packageName
|
||||
*/
|
||||
void resetPackageOpsNoHistory(@NonNull String packageName);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param mode
|
||||
* @param baseSnapshotInterval
|
||||
* @param compressionStep
|
||||
*/
|
||||
void setHistoryParameters(@AppOpsManager.HistoricalMode int mode,
|
||||
long baseSnapshotInterval, int compressionStep);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param offsetMillis
|
||||
*/
|
||||
void offsetHistory(long offsetMillis);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ops
|
||||
*/
|
||||
void addHistoricalOps(AppOpsManager.HistoricalOps ops);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void resetHistoryParameters();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void clearHistory();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param offlineDurationMillis
|
||||
*/
|
||||
void rebootHistory(long offlineDurationMillis);
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class AppOpsUidStateTrackerImpl implements AppOpsUidStateTracker {
|
||||
private final DelayableExecutor mExecutor;
|
||||
private final Clock mClock;
|
||||
private ActivityManagerInternal mActivityManagerInternal;
|
||||
private AppOpsService.Constants mConstants;
|
||||
private AppOpsServiceImpl.Constants mConstants;
|
||||
|
||||
private SparseIntArray mUidStates = new SparseIntArray();
|
||||
private SparseIntArray mPendingUidStates = new SparseIntArray();
|
||||
@@ -85,7 +85,7 @@ class AppOpsUidStateTrackerImpl implements AppOpsUidStateTracker {
|
||||
|
||||
AppOpsUidStateTrackerImpl(ActivityManagerInternal activityManagerInternal,
|
||||
Handler handler, Executor lockingExecutor, Clock clock,
|
||||
AppOpsService.Constants constants) {
|
||||
AppOpsServiceImpl.Constants constants) {
|
||||
|
||||
this(activityManagerInternal, new DelayableExecutor() {
|
||||
@Override
|
||||
@@ -102,7 +102,7 @@ class AppOpsUidStateTrackerImpl implements AppOpsUidStateTracker {
|
||||
|
||||
@VisibleForTesting
|
||||
AppOpsUidStateTrackerImpl(ActivityManagerInternal activityManagerInternal,
|
||||
DelayableExecutor executor, Clock clock, AppOpsService.Constants constants,
|
||||
DelayableExecutor executor, Clock clock, AppOpsServiceImpl.Constants constants,
|
||||
Thread executorThread) {
|
||||
mActivityManagerInternal = activityManagerInternal;
|
||||
mExecutor = executor;
|
||||
|
||||
@@ -40,9 +40,9 @@ import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
final class AttributedOp {
|
||||
private final @NonNull AppOpsService mAppOpsService;
|
||||
private final @NonNull AppOpsServiceImpl mAppOpsService;
|
||||
public final @Nullable String tag;
|
||||
public final @NonNull AppOpsService.Op parent;
|
||||
public final @NonNull AppOpsServiceImpl.Op parent;
|
||||
|
||||
/**
|
||||
* Last successful accesses (noteOp + finished startOp) for each uidState/opFlag combination
|
||||
@@ -80,8 +80,8 @@ final class AttributedOp {
|
||||
// @GuardedBy("mAppOpsService")
|
||||
@Nullable ArrayMap<IBinder, InProgressStartOpEvent> mPausedInProgressEvents;
|
||||
|
||||
AttributedOp(@NonNull AppOpsService appOpsService, @Nullable String tag,
|
||||
@NonNull AppOpsService.Op parent) {
|
||||
AttributedOp(@NonNull AppOpsServiceImpl appOpsService, @Nullable String tag,
|
||||
@NonNull AppOpsServiceImpl.Op parent) {
|
||||
mAppOpsService = appOpsService;
|
||||
this.tag = tag;
|
||||
this.parent = parent;
|
||||
@@ -131,8 +131,8 @@ final class AttributedOp {
|
||||
|
||||
AppOpsManager.OpEventProxyInfo proxyInfo = null;
|
||||
if (proxyUid != Process.INVALID_UID) {
|
||||
proxyInfo = mAppOpsService.mOpEventProxyInfoPool.acquire(proxyUid, proxyPackageName,
|
||||
proxyAttributionTag);
|
||||
proxyInfo = mAppOpsService.mOpEventProxyInfoPool.acquire(proxyUid,
|
||||
proxyPackageName, proxyAttributionTag);
|
||||
}
|
||||
|
||||
AppOpsManager.NoteOpEvent existingEvent = mAccessEvents.get(key);
|
||||
@@ -238,7 +238,7 @@ final class AttributedOp {
|
||||
if (event == null) {
|
||||
event = mAppOpsService.mInProgressStartOpEventPool.acquire(startTime,
|
||||
SystemClock.elapsedRealtime(), clientId, tag,
|
||||
PooledLambda.obtainRunnable(AppOpsService::onClientDeath, this, clientId),
|
||||
PooledLambda.obtainRunnable(AppOpsServiceImpl::onClientDeath, this, clientId),
|
||||
proxyUid, proxyPackageName, proxyAttributionTag, uidState, flags,
|
||||
attributionFlags, attributionChainId);
|
||||
events.put(clientId, event);
|
||||
@@ -251,9 +251,9 @@ final class AttributedOp {
|
||||
event.mNumUnfinishedStarts++;
|
||||
|
||||
if (isStarted) {
|
||||
mAppOpsService.mHistoricalRegistry.incrementOpAccessedCount(parent.op, parent.uid,
|
||||
parent.packageName, tag, uidState, flags, startTime, attributionFlags,
|
||||
attributionChainId);
|
||||
mAppOpsService.mHistoricalRegistry.incrementOpAccessedCount(parent.op,
|
||||
parent.uid, parent.packageName, tag, uidState, flags, startTime,
|
||||
attributionFlags, attributionChainId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,8 +309,8 @@ final class AttributedOp {
|
||||
mAccessEvents.put(makeKey(event.getUidState(), event.getFlags()),
|
||||
finishedEvent);
|
||||
|
||||
mAppOpsService.mHistoricalRegistry.increaseOpAccessDuration(parent.op, parent.uid,
|
||||
parent.packageName, tag, event.getUidState(),
|
||||
mAppOpsService.mHistoricalRegistry.increaseOpAccessDuration(parent.op,
|
||||
parent.uid, parent.packageName, tag, event.getUidState(),
|
||||
event.getFlags(), finishedEvent.getNoteTime(), finishedEvent.getDuration(),
|
||||
event.getAttributionFlags(), event.getAttributionChainId());
|
||||
|
||||
@@ -334,13 +334,13 @@ final class AttributedOp {
|
||||
@SuppressWarnings("GuardedBy") // Lock is held on mAppOpsService
|
||||
private void finishPossiblyPaused(@NonNull IBinder clientId, boolean isPausing) {
|
||||
if (!isPaused()) {
|
||||
Slog.wtf(AppOpsService.TAG, "No ops running or paused");
|
||||
Slog.wtf(AppOpsServiceImpl.TAG, "No ops running or paused");
|
||||
return;
|
||||
}
|
||||
|
||||
int indexOfToken = mPausedInProgressEvents.indexOfKey(clientId);
|
||||
if (indexOfToken < 0) {
|
||||
Slog.wtf(AppOpsService.TAG, "No op running or paused for the client");
|
||||
Slog.wtf(AppOpsServiceImpl.TAG, "No op running or paused for the client");
|
||||
return;
|
||||
} else if (isPausing) {
|
||||
// already paused
|
||||
@@ -416,9 +416,9 @@ final class AttributedOp {
|
||||
mInProgressEvents.put(event.getClientId(), event);
|
||||
event.setStartElapsedTime(SystemClock.elapsedRealtime());
|
||||
event.setStartTime(startTime);
|
||||
mAppOpsService.mHistoricalRegistry.incrementOpAccessedCount(parent.op, parent.uid,
|
||||
parent.packageName, tag, event.getUidState(), event.getFlags(), startTime,
|
||||
event.getAttributionFlags(), event.getAttributionChainId());
|
||||
mAppOpsService.mHistoricalRegistry.incrementOpAccessedCount(parent.op,
|
||||
parent.uid, parent.packageName, tag, event.getUidState(), event.getFlags(),
|
||||
startTime, event.getAttributionFlags(), event.getAttributionChainId());
|
||||
if (shouldSendActive) {
|
||||
mAppOpsService.scheduleOpActiveChangedIfNeededLocked(parent.op, parent.uid,
|
||||
parent.packageName, tag, true, event.getAttributionFlags(),
|
||||
@@ -503,8 +503,8 @@ final class AttributedOp {
|
||||
newEvent.mNumUnfinishedStarts += numPreviousUnfinishedStarts - 1;
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
if (AppOpsService.DEBUG) {
|
||||
Slog.e(AppOpsService.TAG,
|
||||
if (AppOpsServiceImpl.DEBUG) {
|
||||
Slog.e(AppOpsServiceImpl.TAG,
|
||||
"Cannot switch to new uidState " + newState);
|
||||
}
|
||||
}
|
||||
@@ -555,8 +555,8 @@ final class AttributedOp {
|
||||
ArrayMap<IBinder, InProgressStartOpEvent> ignoredEvents =
|
||||
opToAdd.isRunning()
|
||||
? opToAdd.mInProgressEvents : opToAdd.mPausedInProgressEvents;
|
||||
Slog.w(AppOpsService.TAG, "Ignoring " + ignoredEvents.size() + " app-ops, running: "
|
||||
+ opToAdd.isRunning());
|
||||
Slog.w(AppOpsServiceImpl.TAG, "Ignoring " + ignoredEvents.size()
|
||||
+ " app-ops, running: " + opToAdd.isRunning());
|
||||
|
||||
int numInProgressEvents = ignoredEvents.size();
|
||||
for (int i = 0; i < numInProgressEvents; i++) {
|
||||
@@ -668,16 +668,22 @@ final class AttributedOp {
|
||||
/**
|
||||
* Create a new {@link InProgressStartOpEvent}.
|
||||
*
|
||||
* @param startTime The time {@link #startOperation} was called
|
||||
* @param startElapsedTime The elapsed time when {@link #startOperation} was called
|
||||
* @param clientId The client id of the caller of {@link #startOperation}
|
||||
* @param startTime The time {@link AppOpCheckingServiceInterface#startOperation}
|
||||
* was called
|
||||
* @param startElapsedTime The elapsed time whe
|
||||
* {@link AppOpCheckingServiceInterface#startOperation} was called
|
||||
* @param clientId The client id of the caller of
|
||||
* {@link AppOpCheckingServiceInterface#startOperation}
|
||||
* @param attributionTag The attribution tag for the operation.
|
||||
* @param onDeath The code to execute on client death
|
||||
* @param uidState The uidstate of the app {@link #startOperation} was called for
|
||||
* @param uidState The uidstate of the app
|
||||
* {@link AppOpCheckingServiceInterface#startOperation} was called
|
||||
* for
|
||||
* @param attributionFlags the attribution flags for this operation.
|
||||
* @param attributionChainId the unique id of the attribution chain this op is a part of.
|
||||
* @param proxy The proxy information, if {@link #startProxyOperation} was
|
||||
* called
|
||||
* @param proxy The proxy information, if
|
||||
* {@link AppOpCheckingServiceInterface#startProxyOperation} was
|
||||
* called
|
||||
* @param flags The trusted/nontrusted/self flags.
|
||||
* @throws RemoteException If the client is dying
|
||||
*/
|
||||
@@ -718,15 +724,21 @@ final class AttributedOp {
|
||||
/**
|
||||
* Reinit existing object with new state.
|
||||
*
|
||||
* @param startTime The time {@link #startOperation} was called
|
||||
* @param startElapsedTime The elapsed time when {@link #startOperation} was called
|
||||
* @param clientId The client id of the caller of {@link #startOperation}
|
||||
* @param startTime The time {@link AppOpCheckingServiceInterface#startOperation}
|
||||
* was called
|
||||
* @param startElapsedTime The elapsed time when
|
||||
* {@link AppOpCheckingServiceInterface#startOperation} was called
|
||||
* @param clientId The client id of the caller of
|
||||
* {@link AppOpCheckingServiceInterface#startOperation}
|
||||
* @param attributionTag The attribution tag for this operation.
|
||||
* @param onDeath The code to execute on client death
|
||||
* @param uidState The uidstate of the app {@link #startOperation} was called for
|
||||
* @param uidState The uidstate of the app
|
||||
* {@link AppOpCheckingServiceInterface#startOperation} was called
|
||||
* for
|
||||
* @param flags The flags relating to the proxy
|
||||
* @param proxy The proxy information, if {@link #startProxyOperation}
|
||||
* was called
|
||||
* @param proxy The proxy information, if
|
||||
* {@link AppOpCheckingServiceInterface#startProxyOperation was
|
||||
* called
|
||||
* @param attributionFlags the attribution flags for this operation.
|
||||
* @param attributionChainId the unique id of the attribution chain this op is a part of.
|
||||
* @param proxyPool The pool to release
|
||||
|
||||
@@ -48,7 +48,7 @@ public class AppOpsLegacyRestrictionsTest {
|
||||
StaticMockitoSession mSession;
|
||||
|
||||
@Mock
|
||||
AppOpsService.Constants mConstants;
|
||||
AppOpsServiceImpl.Constants mConstants;
|
||||
|
||||
@Mock
|
||||
Context mContext;
|
||||
@@ -57,7 +57,7 @@ public class AppOpsLegacyRestrictionsTest {
|
||||
Handler mHandler;
|
||||
|
||||
@Mock
|
||||
AppOpsServiceInterface mLegacyAppOpsService;
|
||||
AppOpsCheckingServiceInterface mLegacyAppOpsService;
|
||||
|
||||
AppOpsRestrictions mAppOpsRestrictions;
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ import static android.app.AppOpsManager.OP_FLAGS_ALL;
|
||||
import static android.app.AppOpsManager.OP_READ_SMS;
|
||||
import static android.app.AppOpsManager.OP_WIFI_SCAN;
|
||||
import static android.app.AppOpsManager.OP_WRITE_SMS;
|
||||
import static android.app.AppOpsManager.resolvePackageName;
|
||||
import static android.os.Process.INVALID_UID;
|
||||
|
||||
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
|
||||
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
|
||||
@@ -39,6 +41,7 @@ import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
|
||||
import android.app.AppOpsManager;
|
||||
import android.app.AppOpsManager.OpEntry;
|
||||
import android.app.AppOpsManager.PackageOps;
|
||||
import android.content.ContentResolver;
|
||||
@@ -86,13 +89,13 @@ public class AppOpsServiceTest {
|
||||
|
||||
private File mAppOpsFile;
|
||||
private Handler mHandler;
|
||||
private AppOpsService mAppOpsService;
|
||||
private AppOpsServiceImpl mAppOpsService;
|
||||
private int mMyUid;
|
||||
private long mTestStartMillis;
|
||||
private StaticMockitoSession mMockingSession;
|
||||
|
||||
private void setupAppOpsService() {
|
||||
mAppOpsService = new AppOpsService(mAppOpsFile, mHandler, spy(sContext));
|
||||
mAppOpsService = new AppOpsServiceImpl(mAppOpsFile, mHandler, spy(sContext));
|
||||
mAppOpsService.mHistoricalRegistry.systemReady(sContext.getContentResolver());
|
||||
|
||||
// Always approve all permission checks
|
||||
@@ -161,17 +164,20 @@ public class AppOpsServiceTest {
|
||||
|
||||
@Test
|
||||
public void testNoteOperationAndGetOpsForPackage() {
|
||||
mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED);
|
||||
mAppOpsService.setMode(OP_WRITE_SMS, mMyUid, sMyPackageName, MODE_ERRORED);
|
||||
mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED, null);
|
||||
mAppOpsService.setMode(OP_WRITE_SMS, mMyUid, sMyPackageName, MODE_ERRORED, null);
|
||||
|
||||
// Note an op that's allowed.
|
||||
mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null, false);
|
||||
mAppOpsService.noteOperationUnchecked(OP_READ_SMS, mMyUid,
|
||||
resolvePackageName(mMyUid, sMyPackageName), null,
|
||||
INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF);
|
||||
List<PackageOps> loggedOps = getLoggedOps();
|
||||
assertContainsOp(loggedOps, OP_READ_SMS, mTestStartMillis, -1, MODE_ALLOWED);
|
||||
|
||||
// Note another op that's not allowed.
|
||||
mAppOpsService.noteOperation(OP_WRITE_SMS, mMyUid, sMyPackageName, null, false, null,
|
||||
false);
|
||||
mAppOpsService.noteOperationUnchecked(OP_WRITE_SMS, mMyUid,
|
||||
resolvePackageName(mMyUid, sMyPackageName), null,
|
||||
INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF);
|
||||
loggedOps = getLoggedOps();
|
||||
assertContainsOp(loggedOps, OP_READ_SMS, mTestStartMillis, -1, MODE_ALLOWED);
|
||||
assertContainsOp(loggedOps, OP_WRITE_SMS, -1, mTestStartMillis, MODE_ERRORED);
|
||||
@@ -185,18 +191,20 @@ public class AppOpsServiceTest {
|
||||
@Test
|
||||
public void testNoteOperationAndGetOpsForPackage_controlledByDifferentOp() {
|
||||
// This op controls WIFI_SCAN
|
||||
mAppOpsService.setMode(OP_COARSE_LOCATION, mMyUid, sMyPackageName, MODE_ALLOWED);
|
||||
mAppOpsService.setMode(OP_COARSE_LOCATION, mMyUid, sMyPackageName, MODE_ALLOWED, null);
|
||||
|
||||
assertThat(mAppOpsService.noteOperation(OP_WIFI_SCAN, mMyUid, sMyPackageName, null, false,
|
||||
null, false).getOpMode()).isEqualTo(MODE_ALLOWED);
|
||||
assertThat(mAppOpsService.noteOperationUnchecked(OP_WIFI_SCAN, mMyUid,
|
||||
resolvePackageName(mMyUid, sMyPackageName), null,
|
||||
INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF)).isEqualTo(MODE_ALLOWED);
|
||||
|
||||
assertContainsOp(getLoggedOps(), OP_WIFI_SCAN, mTestStartMillis, -1,
|
||||
MODE_ALLOWED /* default for WIFI_SCAN; this is not changed or used in this test */);
|
||||
|
||||
// Now set COARSE_LOCATION to ERRORED -> this will make WIFI_SCAN disabled as well.
|
||||
mAppOpsService.setMode(OP_COARSE_LOCATION, mMyUid, sMyPackageName, MODE_ERRORED);
|
||||
assertThat(mAppOpsService.noteOperation(OP_WIFI_SCAN, mMyUid, sMyPackageName, null, false,
|
||||
null, false).getOpMode()).isEqualTo(MODE_ERRORED);
|
||||
mAppOpsService.setMode(OP_COARSE_LOCATION, mMyUid, sMyPackageName, MODE_ERRORED, null);
|
||||
assertThat(mAppOpsService.noteOperationUnchecked(OP_WIFI_SCAN, mMyUid,
|
||||
resolvePackageName(mMyUid, sMyPackageName), null,
|
||||
INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF)).isEqualTo(MODE_ERRORED);
|
||||
|
||||
assertContainsOp(getLoggedOps(), OP_WIFI_SCAN, mTestStartMillis, mTestStartMillis,
|
||||
MODE_ALLOWED /* default for WIFI_SCAN; this is not changed or used in this test */);
|
||||
@@ -205,11 +213,14 @@ public class AppOpsServiceTest {
|
||||
// Tests the dumping and restoring of the in-memory state to/from XML.
|
||||
@Test
|
||||
public void testStatePersistence() {
|
||||
mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED);
|
||||
mAppOpsService.setMode(OP_WRITE_SMS, mMyUid, sMyPackageName, MODE_ERRORED);
|
||||
mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null, false);
|
||||
mAppOpsService.noteOperation(OP_WRITE_SMS, mMyUid, sMyPackageName, null, false, null,
|
||||
false);
|
||||
mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED, null);
|
||||
mAppOpsService.setMode(OP_WRITE_SMS, mMyUid, sMyPackageName, MODE_ERRORED, null);
|
||||
mAppOpsService.noteOperationUnchecked(OP_READ_SMS, mMyUid,
|
||||
resolvePackageName(mMyUid, sMyPackageName), null,
|
||||
INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF);
|
||||
mAppOpsService.noteOperationUnchecked(OP_WRITE_SMS, mMyUid,
|
||||
resolvePackageName(mMyUid, sMyPackageName), null,
|
||||
INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF);
|
||||
mAppOpsService.writeState();
|
||||
|
||||
// Create a new app ops service which will initialize its state from XML.
|
||||
@@ -224,8 +235,10 @@ public class AppOpsServiceTest {
|
||||
// Tests that ops are persisted during shutdown.
|
||||
@Test
|
||||
public void testShutdown() {
|
||||
mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED);
|
||||
mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null, false);
|
||||
mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED, null);
|
||||
mAppOpsService.noteOperationUnchecked(OP_READ_SMS, mMyUid,
|
||||
resolvePackageName(mMyUid, sMyPackageName), null,
|
||||
INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF);
|
||||
mAppOpsService.shutdown();
|
||||
|
||||
// Create a new app ops service which will initialize its state from XML.
|
||||
@@ -238,8 +251,10 @@ public class AppOpsServiceTest {
|
||||
|
||||
@Test
|
||||
public void testGetOpsForPackage() {
|
||||
mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED);
|
||||
mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null, false);
|
||||
mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED, null);
|
||||
mAppOpsService.noteOperationUnchecked(OP_READ_SMS, mMyUid,
|
||||
resolvePackageName(mMyUid, sMyPackageName), null,
|
||||
INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF);
|
||||
|
||||
// Query all ops
|
||||
List<PackageOps> loggedOps = mAppOpsService.getOpsForPackage(
|
||||
@@ -267,8 +282,10 @@ public class AppOpsServiceTest {
|
||||
|
||||
@Test
|
||||
public void testPackageRemoved() {
|
||||
mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED);
|
||||
mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null, false);
|
||||
mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED, null);
|
||||
mAppOpsService.noteOperationUnchecked(OP_READ_SMS, mMyUid,
|
||||
resolvePackageName(mMyUid, sMyPackageName), null,
|
||||
INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF);
|
||||
|
||||
List<PackageOps> loggedOps = getLoggedOps();
|
||||
assertContainsOp(loggedOps, OP_READ_SMS, mTestStartMillis, -1, MODE_ALLOWED);
|
||||
@@ -322,8 +339,10 @@ public class AppOpsServiceTest {
|
||||
|
||||
@Test
|
||||
public void testUidRemoved() {
|
||||
mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED);
|
||||
mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null, false);
|
||||
mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED, null);
|
||||
mAppOpsService.noteOperationUnchecked(OP_READ_SMS, mMyUid,
|
||||
resolvePackageName(mMyUid, sMyPackageName), null,
|
||||
INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF);
|
||||
|
||||
List<PackageOps> loggedOps = getLoggedOps();
|
||||
assertContainsOp(loggedOps, OP_READ_SMS, mTestStartMillis, -1, MODE_ALLOWED);
|
||||
|
||||
@@ -76,7 +76,7 @@ public class AppOpsUidStateTrackerTest {
|
||||
ActivityManagerInternal mAmi;
|
||||
|
||||
@Mock
|
||||
AppOpsService.Constants mConstants;
|
||||
AppOpsServiceImpl.Constants mConstants;
|
||||
|
||||
AppOpsUidStateTrackerTestExecutor mExecutor = new AppOpsUidStateTrackerTestExecutor();
|
||||
|
||||
|
||||
@@ -93,12 +93,13 @@ public class AppOpsUpgradeTest {
|
||||
}
|
||||
}
|
||||
|
||||
private void assertSameModes(SparseArray<AppOpsService.UidState> uidStates, int op1, int op2) {
|
||||
private void assertSameModes(SparseArray<AppOpsServiceImpl.UidState> uidStates,
|
||||
int op1, int op2) {
|
||||
int numberOfNonDefaultOps = 0;
|
||||
final int defaultModeOp1 = AppOpsManager.opToDefaultMode(op1);
|
||||
final int defaultModeOp2 = AppOpsManager.opToDefaultMode(op2);
|
||||
for(int i = 0; i < uidStates.size(); i++) {
|
||||
final AppOpsService.UidState uidState = uidStates.valueAt(i);
|
||||
final AppOpsServiceImpl.UidState uidState = uidStates.valueAt(i);
|
||||
SparseIntArray opModes = uidState.getNonDefaultUidModes();
|
||||
if (opModes != null) {
|
||||
final int uidMode1 = opModes.get(op1, defaultModeOp1);
|
||||
@@ -112,12 +113,12 @@ public class AppOpsUpgradeTest {
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < uidState.pkgOps.size(); j++) {
|
||||
final AppOpsService.Ops ops = uidState.pkgOps.valueAt(j);
|
||||
final AppOpsServiceImpl.Ops ops = uidState.pkgOps.valueAt(j);
|
||||
if (ops == null) {
|
||||
continue;
|
||||
}
|
||||
final AppOpsService.Op _op1 = ops.get(op1);
|
||||
final AppOpsService.Op _op2 = ops.get(op2);
|
||||
final AppOpsServiceImpl.Op _op1 = ops.get(op1);
|
||||
final AppOpsServiceImpl.Op _op2 = ops.get(op2);
|
||||
final int mode1 = (_op1 == null) ? defaultModeOp1 : _op1.getMode();
|
||||
final int mode2 = (_op2 == null) ? defaultModeOp2 : _op2.getMode();
|
||||
assertEquals(mode1, mode2);
|
||||
@@ -158,8 +159,8 @@ public class AppOpsUpgradeTest {
|
||||
// Stub out package calls to disable AppOpsService#updatePermissionRevokedCompat
|
||||
when(testPM.getPackagesForUid(anyInt())).thenReturn(null);
|
||||
|
||||
AppOpsService testService = spy(
|
||||
new AppOpsService(mAppOpsFile, mHandler, testContext)); // trigger upgrade
|
||||
AppOpsServiceImpl testService = spy(
|
||||
new AppOpsServiceImpl(mAppOpsFile, mHandler, testContext)); // trigger upgrade
|
||||
assertSameModes(testService.mUidStates, AppOpsManager.OP_RUN_IN_BACKGROUND,
|
||||
AppOpsManager.OP_RUN_ANY_IN_BACKGROUND);
|
||||
mHandler.removeCallbacks(testService.mWriteRunner);
|
||||
|
||||
Reference in New Issue
Block a user