Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 06b1df65 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use start/finish app ops in window manager"

parents 364eb306 f7b47253
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -48,7 +48,10 @@ package android.app {


  public class AppOpsManager {
  public class AppOpsManager {
    method public static java.lang.String[] getOpStrs();
    method public static java.lang.String[] getOpStrs();
    method public boolean isOperationActive(int, int, java.lang.String);
    method public void setMode(int, int, java.lang.String, int);
    method public void setMode(int, int, java.lang.String, int);
    method public void startWatchingActive(int[], android.app.AppOpsManager.OnOpActiveChangedListener);
    method public void stopWatchingActive(android.app.AppOpsManager.OnOpActiveChangedListener);
    field public static final java.lang.String OPSTR_ACCEPT_HANDOVER = "android:accept_handover";
    field public static final java.lang.String OPSTR_ACCEPT_HANDOVER = "android:accept_handover";
    field public static final java.lang.String OPSTR_ACCESS_NOTIFICATIONS = "android:access_notifications";
    field public static final java.lang.String OPSTR_ACCESS_NOTIFICATIONS = "android:access_notifications";
    field public static final java.lang.String OPSTR_ACTIVATE_VPN = "android:activate_vpn";
    field public static final java.lang.String OPSTR_ACTIVATE_VPN = "android:activate_vpn";
@@ -90,6 +93,11 @@ package android.app {
    field public static final java.lang.String OPSTR_WRITE_ICC_SMS = "android:write_icc_sms";
    field public static final java.lang.String OPSTR_WRITE_ICC_SMS = "android:write_icc_sms";
    field public static final java.lang.String OPSTR_WRITE_SMS = "android:write_sms";
    field public static final java.lang.String OPSTR_WRITE_SMS = "android:write_sms";
    field public static final java.lang.String OPSTR_WRITE_WALLPAPER = "android:write_wallpaper";
    field public static final java.lang.String OPSTR_WRITE_WALLPAPER = "android:write_wallpaper";
    field public static final int OP_SYSTEM_ALERT_WINDOW = 24; // 0x18
  }

  public static abstract interface AppOpsManager.OnOpActiveChangedListener {
    method public abstract void onOpActiveChanged(int, int, java.lang.String, boolean);
  }
  }


  public final class NotificationChannelGroup implements android.os.Parcelable {
  public final class NotificationChannelGroup implements android.os.Parcelable {
+82 −27
Original line number Original line Diff line number Diff line
@@ -31,7 +31,6 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;
import android.os.Process;
import android.os.Process;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager;
import android.util.ArrayMap;
import android.util.ArrayMap;


@@ -168,6 +167,7 @@ public class AppOpsManager {
    /** @hide */
    /** @hide */
    public static final int OP_WRITE_SETTINGS = 23;
    public static final int OP_WRITE_SETTINGS = 23;
    /** @hide Required to draw on top of other apps. */
    /** @hide Required to draw on top of other apps. */
    @TestApi
    public static final int OP_SYSTEM_ALERT_WINDOW = 24;
    public static final int OP_SYSTEM_ALERT_WINDOW = 24;
    /** @hide */
    /** @hide */
    public static final int OP_ACCESS_NOTIFICATIONS = 25;
    public static final int OP_ACCESS_NOTIFICATIONS = 25;
@@ -1540,6 +1540,7 @@ public class AppOpsManager {
     *
     *
     * @hide
     * @hide
     */
     */
    @TestApi
    public interface OnOpActiveChangedListener {
    public interface OnOpActiveChangedListener {
        /**
        /**
         * Called when the active state of an app op changes.
         * Called when the active state of an app op changes.
@@ -1731,7 +1732,7 @@ public class AppOpsManager {
     * Monitor for changes to the operating mode for the given op in the given app package.
     * Monitor for changes to the operating mode for the given op in the given app package.
     *
     *
     * <p> If you don't hold the {@link android.Manifest.permission#WATCH_APPOPS} permission
     * <p> If you don't hold the {@link android.Manifest.permission#WATCH_APPOPS} permission
     * to watch changes only for your UID.
     * you can watch changes only for your UID.
     *
     *
     * @param op The operation to monitor, one of OP_*.
     * @param op The operation to monitor, one of OP_*.
     * @param packageName The name of the application to monitor.
     * @param packageName The name of the application to monitor.
@@ -1787,6 +1788,9 @@ public class AppOpsManager {
     * watched ops for a registered callback you need to unregister and register it
     * watched ops for a registered callback you need to unregister and register it
     * again.
     * again.
     *
     *
     * <p> If you don't hold the {@link android.Manifest.permission#WATCH_APPOPS} permission
     * you can watch changes only for your UID.
     *
     * @param ops The ops to watch.
     * @param ops The ops to watch.
     * @param callback Where to report changes.
     * @param callback Where to report changes.
     *
     *
@@ -1797,7 +1801,9 @@ public class AppOpsManager {
     *
     *
     * @hide
     * @hide
     */
     */
    @RequiresPermission(Manifest.permission.WATCH_APPOPS)
    @TestApi
    // TODO: Uncomment below annotation once b/73559440 is fixed
    // @RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true)
    public void startWatchingActive(@NonNull int[] ops,
    public void startWatchingActive(@NonNull int[] ops,
            @NonNull OnOpActiveChangedListener callback) {
            @NonNull OnOpActiveChangedListener callback) {
        Preconditions.checkNotNull(ops, "ops cannot be null");
        Preconditions.checkNotNull(ops, "ops cannot be null");
@@ -1835,6 +1841,7 @@ public class AppOpsManager {
     *
     *
     * @hide
     * @hide
     */
     */
    @TestApi
    public void stopWatchingActive(@NonNull OnOpActiveChangedListener callback) {
    public void stopWatchingActive(@NonNull OnOpActiveChangedListener callback) {
        synchronized (mActiveWatchers) {
        synchronized (mActiveWatchers) {
            final IAppOpsActiveCallback cb = mActiveWatchers.get(callback);
            final IAppOpsActiveCallback cb = mActiveWatchers.get(callback);
@@ -2086,15 +2093,11 @@ public class AppOpsManager {
     * @hide
     * @hide
     */
     */
    public int noteOp(int op, int uid, String packageName) {
    public int noteOp(int op, int uid, String packageName) {
        try {
        final int mode = noteOpNoThrow(op, uid, packageName);
            int mode = mService.noteOperation(op, uid, packageName);
        if (mode == MODE_ERRORED) {
        if (mode == MODE_ERRORED) {
            throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName));
            throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName));
        }
        }
        return mode;
        return mode;
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
    }


    /**
    /**
@@ -2173,6 +2176,11 @@ public class AppOpsManager {
        }
        }
    }
    }


    /** @hide */
    public int startOp(int op) {
        return startOp(op, Process.myUid(), mContext.getOpPackageName());
    }

    /**
    /**
     * Report that an application has started executing a long-running operation.  Note that you
     * Report that an application has started executing a long-running operation.  Note that you
     * must pass in both the uid and name of the application to be checked; this function will
     * must pass in both the uid and name of the application to be checked; this function will
@@ -2181,6 +2189,7 @@ public class AppOpsManager {
     * the current time and the operation will be marked as "running".  In this case you must
     * the current time and the operation will be marked as "running".  In this case you must
     * later call {@link #finishOp(int, int, String)} to report when the application is no
     * later call {@link #finishOp(int, int, String)} to report when the application is no
     * longer performing the operation.
     * longer performing the operation.
     *
     * @param op The operation to start.  One of the OP_* constants.
     * @param op The operation to start.  One of the OP_* constants.
     * @param uid The user id of the application attempting to perform the operation.
     * @param uid The user id of the application attempting to perform the operation.
     * @param packageName The name of the application attempting to perform the operation.
     * @param packageName The name of the application attempting to perform the operation.
@@ -2191,15 +2200,34 @@ public class AppOpsManager {
     * @hide
     * @hide
     */
     */
    public int startOp(int op, int uid, String packageName) {
    public int startOp(int op, int uid, String packageName) {
        try {
        return startOp(op, uid, packageName, false);
            int mode = mService.startOperation(getToken(mService), op, uid, packageName);
    }

    /**
     * Report that an application has started executing a long-running operation. Similar
     * to {@link #startOp(String, int, String) except that if the mode is {@link #MODE_DEFAULT}
     * the operation should succeed since the caller has performed its standard permission
     * checks which passed and would perform the protected operation for this mode.
     *
     * @param op The operation to start.  One of the OP_* constants.
     * @param uid The user id of the application attempting to perform the operation.
     * @param packageName The name of the application attempting to perform the operation.
     * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
     * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
     * causing the app to crash).
     * @param startIfModeDefault Whether to start if mode is {@link #MODE_DEFAULT}.
     *
     * @throws SecurityException If the app has been configured to crash on this op or
     * the package is not in the passed in UID.
     *
     * @hide
     */
    public int startOp(int op, int uid, String packageName, boolean startIfModeDefault) {
        final int mode = startOpNoThrow(op, uid, packageName, startIfModeDefault);
        if (mode == MODE_ERRORED) {
        if (mode == MODE_ERRORED) {
            throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName));
            throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName));
        }
        }
        return mode;
        return mode;
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
    }


    /**
    /**
@@ -2208,18 +2236,32 @@ public class AppOpsManager {
     * @hide
     * @hide
     */
     */
    public int startOpNoThrow(int op, int uid, String packageName) {
    public int startOpNoThrow(int op, int uid, String packageName) {
        return startOpNoThrow(op, uid, packageName, false);
    }

    /**
     * Like {@link #startOp(int, int, String, boolean)} but instead of throwing a
     * {@link SecurityException} it returns {@link #MODE_ERRORED}.
     *
     * @param op The operation to start.  One of the OP_* constants.
     * @param uid The user id of the application attempting to perform the operation.
     * @param packageName The name of the application attempting to perform the operation.
     * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
     * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
     * causing the app to crash).
     * @param startIfModeDefault Whether to start if mode is {@link #MODE_DEFAULT}.
     *
     * @hide
     */
    public int startOpNoThrow(int op, int uid, String packageName, boolean startIfModeDefault) {
        try {
        try {
            return mService.startOperation(getToken(mService), op, uid, packageName);
            return mService.startOperation(getToken(mService), op, uid, packageName,
                    startIfModeDefault);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
    }
    }


    /** @hide */
    public int startOp(int op) {
        return startOp(op, Process.myUid(), mContext.getOpPackageName());
    }

    /**
    /**
     * Report that an application is no longer performing an operation that had previously
     * Report that an application is no longer performing an operation that had previously
     * been started with {@link #startOp(int, int, String)}.  There is no validation of input
     * been started with {@link #startOp(int, int, String)}.  There is no validation of input
@@ -2240,8 +2282,21 @@ public class AppOpsManager {
        finishOp(op, Process.myUid(), mContext.getOpPackageName());
        finishOp(op, Process.myUid(), mContext.getOpPackageName());
    }
    }


    /** @hide */
    /**
    @RequiresPermission(Manifest.permission.WATCH_APPOPS)
     * Checks whether the given op for a UID and package is active.
     *
     * <p> If you don't hold the {@link android.Manifest.permission#WATCH_APPOPS} permission
     * you can query only for your UID.
     *
     * @see #startWatchingActive(int[], OnOpActiveChangedListener)
     * @see #stopWatchingMode(OnOpChangedListener)
     * @see #finishOp(int)
     * @see #startOp(int)
     *
     * @hide */
    @TestApi
    // TODO: Uncomment below annotation once b/73559440 is fixed
    // @RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true)
    public boolean isOperationActive(int code, int uid, String packageName) {
    public boolean isOperationActive(int code, int uid, String packageName) {
        try {
        try {
            return mService.isOperationActive(code, uid, packageName);
            return mService.isOperationActive(code, uid, packageName);
+2 −1
Original line number Original line Diff line number Diff line
@@ -26,7 +26,8 @@ interface IAppOpsService {
    // be kept in sync with frameworks/native/libs/binder/include/binder/IAppOpsService.h
    // be kept in sync with frameworks/native/libs/binder/include/binder/IAppOpsService.h
    int checkOperation(int code, int uid, String packageName);
    int checkOperation(int code, int uid, String packageName);
    int noteOperation(int code, int uid, String packageName);
    int noteOperation(int code, int uid, String packageName);
    int startOperation(IBinder token, int code, int uid, String packageName);
    int startOperation(IBinder token, int code, int uid, String packageName,
            boolean startIfModeDefault);
    void finishOperation(IBinder token, int code, int uid, String packageName);
    void finishOperation(IBinder token, int code, int uid, String packageName);
    void startWatchingMode(int op, String packageName, IAppOpsCallback callback);
    void startWatchingMode(int op, String packageName, IAppOpsCallback callback);
    void stopWatchingMode(IAppOpsCallback callback);
    void stopWatchingMode(IAppOpsCallback callback);
+33 −24
Original line number Original line Diff line number Diff line
@@ -211,9 +211,11 @@ public class AppOpsService extends IAppOpsService.Stub {


    public final class ActiveCallback implements DeathRecipient {
    public final class ActiveCallback implements DeathRecipient {
        final IAppOpsActiveCallback mCallback;
        final IAppOpsActiveCallback mCallback;
        final int mUid;


        public ActiveCallback(IAppOpsActiveCallback callback) {
        public ActiveCallback(IAppOpsActiveCallback callback, int uid) {
            mCallback = callback;
            mCallback = callback;
            mUid = uid;
            try {
            try {
                mCallback.asBinder().linkToDeath(this, 0);
                mCallback.asBinder().linkToDeath(this, 0);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
@@ -233,21 +235,19 @@ public class AppOpsService extends IAppOpsService.Stub {
    final ArrayMap<IBinder, ClientState> mClients = new ArrayMap<IBinder, ClientState>();
    final ArrayMap<IBinder, ClientState> mClients = new ArrayMap<IBinder, ClientState>();


    public final class ClientState extends Binder implements DeathRecipient {
    public final class ClientState extends Binder implements DeathRecipient {
        final ArrayList<Op> mStartedOps = new ArrayList<>();
        final IBinder mAppToken;
        final IBinder mAppToken;
        final int mPid;
        final int mPid;
        final ArrayList<Op> mStartedOps;


        public ClientState(IBinder appToken) {
        public ClientState(IBinder appToken) {
            mAppToken = appToken;
            mAppToken = appToken;
            mPid = Binder.getCallingPid();
            mPid = Binder.getCallingPid();
            if (appToken instanceof Binder) {
            // Watch only for remote processes dying
                // For local clients, there is no reason to track them.
            if (!(appToken instanceof Binder)) {
                mStartedOps = null;
            } else {
                mStartedOps = new ArrayList<Op>();
                try {
                try {
                    mAppToken.linkToDeath(this, 0);
                    mAppToken.linkToDeath(this, 0);
                } catch (RemoteException e) {
                } catch (RemoteException e) {
                    /* do nothing */
                }
                }
            }
            }
        }
        }
@@ -256,7 +256,7 @@ public class AppOpsService extends IAppOpsService.Stub {
        public String toString() {
        public String toString() {
            return "ClientState{" +
            return "ClientState{" +
                    "mAppToken=" + mAppToken +
                    "mAppToken=" + mAppToken +
                    ", " + (mStartedOps != null ? ("pid=" + mPid) : "local") +
                    ", " + "pid=" + mPid +
                    '}';
                    '}';
        }
        }


@@ -1195,8 +1195,11 @@ public class AppOpsService extends IAppOpsService.Stub {


    @Override
    @Override
    public void startWatchingActive(int[] ops, IAppOpsActiveCallback callback) {
    public void startWatchingActive(int[] ops, IAppOpsActiveCallback callback) {
        mContext.enforceCallingOrSelfPermission(Manifest.permission.WATCH_APPOPS,
        int watchedUid = -1;
                "startWatchingActive");
        if (mContext.checkCallingOrSelfPermission(Manifest.permission.WATCH_APPOPS)
                != PackageManager.PERMISSION_GRANTED) {
            watchedUid = Binder.getCallingUid();
        }
        if (ops != null) {
        if (ops != null) {
            Preconditions.checkArrayElementsInRange(ops, 0,
            Preconditions.checkArrayElementsInRange(ops, 0,
                    AppOpsManager._NUM_OP - 1, "Invalid op code in: " + Arrays.toString(ops));
                    AppOpsManager._NUM_OP - 1, "Invalid op code in: " + Arrays.toString(ops));
@@ -1210,7 +1213,7 @@ public class AppOpsService extends IAppOpsService.Stub {
                callbacks = new SparseArray<>();
                callbacks = new SparseArray<>();
                mActiveWatchers.put(callback.asBinder(), callbacks);
                mActiveWatchers.put(callback.asBinder(), callbacks);
            }
            }
            final ActiveCallback activeCallback = new ActiveCallback(callback);
            final ActiveCallback activeCallback = new ActiveCallback(callback, watchedUid);
            for (int op : ops) {
            for (int op : ops) {
                callbacks.put(op, activeCallback);
                callbacks.put(op, activeCallback);
            }
            }
@@ -1239,7 +1242,8 @@ public class AppOpsService extends IAppOpsService.Stub {
    }
    }


    @Override
    @Override
    public int startOperation(IBinder token, int code, int uid, String packageName) {
    public int startOperation(IBinder token, int code, int uid, String packageName,
            boolean startIfModeDefault) {
        verifyIncomingUid(uid);
        verifyIncomingUid(uid);
        verifyIncomingOp(code);
        verifyIncomingOp(code);
        String resolvedPackageName = resolvePackageName(uid, packageName);
        String resolvedPackageName = resolvePackageName(uid, packageName);
@@ -1265,7 +1269,8 @@ public class AppOpsService extends IAppOpsService.Stub {
            // non-default) it takes over, otherwise use the per package policy.
            // non-default) it takes over, otherwise use the per package policy.
            if (uidState.opModes != null && uidState.opModes.indexOfKey(switchCode) >= 0) {
            if (uidState.opModes != null && uidState.opModes.indexOfKey(switchCode) >= 0) {
                final int uidMode = uidState.opModes.get(switchCode);
                final int uidMode = uidState.opModes.get(switchCode);
                if (uidMode != AppOpsManager.MODE_ALLOWED) {
                if (uidMode != AppOpsManager.MODE_ALLOWED
                        && (!startIfModeDefault || uidMode != AppOpsManager.MODE_DEFAULT)) {
                    if (DEBUG) Slog.d(TAG, "noteOperation: reject #" + op.mode + " for code "
                    if (DEBUG) Slog.d(TAG, "noteOperation: reject #" + op.mode + " for code "
                            + switchCode + " (" + code + ") uid " + uid + " package "
                            + switchCode + " (" + code + ") uid " + uid + " package "
                            + resolvedPackageName);
                            + resolvedPackageName);
@@ -1274,7 +1279,8 @@ public class AppOpsService extends IAppOpsService.Stub {
                }
                }
            } else {
            } else {
                final Op switchOp = switchCode != code ? getOpLocked(ops, switchCode, true) : op;
                final Op switchOp = switchCode != code ? getOpLocked(ops, switchCode, true) : op;
                if (switchOp.mode != AppOpsManager.MODE_ALLOWED) {
                if (switchOp.mode != AppOpsManager.MODE_ALLOWED
                        && (!startIfModeDefault || switchOp.mode != AppOpsManager.MODE_DEFAULT)) {
                    if (DEBUG) Slog.d(TAG, "startOperation: reject #" + op.mode + " for code "
                    if (DEBUG) Slog.d(TAG, "startOperation: reject #" + op.mode + " for code "
                            + switchCode + " (" + code + ") uid " + uid + " package "
                            + switchCode + " (" + code + ") uid " + uid + " package "
                            + resolvedPackageName);
                            + resolvedPackageName);
@@ -1316,12 +1322,10 @@ public class AppOpsService extends IAppOpsService.Stub {
            if (op == null) {
            if (op == null) {
                return;
                return;
            }
            }
            if (client.mStartedOps != null) {
            if (!client.mStartedOps.remove(op)) {
            if (!client.mStartedOps.remove(op)) {
                throw new IllegalStateException("Operation not started: uid" + op.uid
                throw new IllegalStateException("Operation not started: uid" + op.uid
                        + " pkg=" + op.packageName + " op=" + op.op);
                        + " pkg=" + op.packageName + " op=" + op.op);
            }
            }
            }
            finishOperationLocked(op);
            finishOperationLocked(op);
            if (op.nesting <= 0) {
            if (op.nesting <= 0) {
                scheduleOpActiveChangedIfNeededLocked(code, uid, packageName, false);
                scheduleOpActiveChangedIfNeededLocked(code, uid, packageName, false);
@@ -1337,6 +1341,9 @@ public class AppOpsService extends IAppOpsService.Stub {
            final SparseArray<ActiveCallback> callbacks = mActiveWatchers.valueAt(i);
            final SparseArray<ActiveCallback> callbacks = mActiveWatchers.valueAt(i);
            ActiveCallback callback = callbacks.get(code);
            ActiveCallback callback = callbacks.get(code);
            if (callback != null) {
            if (callback != null) {
                if (callback.mUid >= 0 && callback.mUid != uid) {
                    continue;
                }
                if (dispatchedCallbacks == null) {
                if (dispatchedCallbacks == null) {
                    dispatchedCallbacks = new ArraySet<>();
                    dispatchedCallbacks = new ArraySet<>();
                }
                }
@@ -2420,7 +2427,7 @@ public class AppOpsService extends IAppOpsService.Stub {
                    pw.print("    "); pw.print(mClients.keyAt(i)); pw.println(":");
                    pw.print("    "); pw.print(mClients.keyAt(i)); pw.println(":");
                    ClientState cs = mClients.valueAt(i);
                    ClientState cs = mClients.valueAt(i);
                    pw.print("      "); pw.println(cs);
                    pw.print("      "); pw.println(cs);
                    if (cs.mStartedOps != null && cs.mStartedOps.size() > 0) {
                    if (cs.mStartedOps.size() > 0) {
                        pw.println("      Started ops:");
                        pw.println("      Started ops:");
                        for (int j=0; j<cs.mStartedOps.size(); j++) {
                        for (int j=0; j<cs.mStartedOps.size(); j++) {
                            Op op = cs.mStartedOps.get(j);
                            Op op = cs.mStartedOps.get(j);
@@ -2651,8 +2658,12 @@ public class AppOpsService extends IAppOpsService.Stub {


    @Override
    @Override
    public boolean isOperationActive(int code, int uid, String packageName) {
    public boolean isOperationActive(int code, int uid, String packageName) {
        mContext.enforceCallingOrSelfPermission(Manifest.permission.WATCH_APPOPS,
        if (Binder.getCallingUid() != uid) {
                "isOperationActive");
            if (mContext.checkCallingOrSelfPermission(Manifest.permission.WATCH_APPOPS)
                    != PackageManager.PERMISSION_GRANTED) {
                return false;
            }
        }
        verifyIncomingOp(code);
        verifyIncomingOp(code);
        final String resolvedPackageName = resolvePackageName(uid, packageName);
        final String resolvedPackageName = resolvePackageName(uid, packageName);
        if (resolvedPackageName == null) {
        if (resolvedPackageName == null) {
@@ -2661,8 +2672,6 @@ public class AppOpsService extends IAppOpsService.Stub {
        synchronized (AppOpsService.this) {
        synchronized (AppOpsService.this) {
            for (int i = mClients.size() - 1; i >= 0; i--) {
            for (int i = mClients.size() - 1; i >= 0; i--) {
                final ClientState client = mClients.valueAt(i);
                final ClientState client = mClients.valueAt(i);
                if (client.mStartedOps == null) continue;

                for (int j = client.mStartedOps.size() - 1; j >= 0; j--) {
                for (int j = client.mStartedOps.size() - 1; j >= 0; j--) {
                    final Op op = client.mStartedOps.get(j);
                    final Op op = client.mStartedOps.get(j);
                    if (op.op == code && op.uid == uid) return true;
                    if (op.op == code && op.uid == uid) return true;
+8 −19
Original line number Original line Diff line number Diff line
@@ -98,7 +98,7 @@ public class VibratorService extends IVibratorService.Stub


    private final Context mContext;
    private final Context mContext;
    private final PowerManager.WakeLock mWakeLock;
    private final PowerManager.WakeLock mWakeLock;
    private final IAppOpsService mAppOpsService;
    private final AppOpsManager mAppOps;
    private final IBatteryStats mBatteryStatsService;
    private final IBatteryStats mBatteryStatsService;
    private PowerManagerInternal mPowerManagerInternal;
    private PowerManagerInternal mPowerManagerInternal;
    private InputManager mIm;
    private InputManager mIm;
@@ -265,8 +265,7 @@ public class VibratorService extends IVibratorService.Stub
        mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*vibrator*");
        mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*vibrator*");
        mWakeLock.setReferenceCounted(true);
        mWakeLock.setReferenceCounted(true);


        mAppOpsService =
        mAppOps = mContext.getSystemService(AppOpsManager.class);
            IAppOpsService.Stub.asInterface(ServiceManager.getService(Context.APP_OPS_SERVICE));
        mBatteryStatsService = IBatteryStats.Stub.asInterface(ServiceManager.getService(
        mBatteryStatsService = IBatteryStats.Stub.asInterface(ServiceManager.getService(
                BatteryStats.SERVICE_NAME));
                BatteryStats.SERVICE_NAME));


@@ -721,17 +720,10 @@ public class VibratorService extends IVibratorService.Stub
    }
    }


    private int getAppOpMode(Vibration vib) {
    private int getAppOpMode(Vibration vib) {
        int mode;
        int mode = mAppOps.checkAudioOpNoThrow(AppOpsManager.OP_VIBRATE,
        try {
            mode = mAppOpsService.checkAudioOperation(AppOpsManager.OP_VIBRATE,
                vib.usageHint, vib.uid, vib.opPkg);
                vib.usageHint, vib.uid, vib.opPkg);
        if (mode == AppOpsManager.MODE_ALLOWED) {
        if (mode == AppOpsManager.MODE_ALLOWED) {
                mode = mAppOpsService.startOperation(AppOpsManager.getToken(mAppOpsService),
            mode = mAppOps.startOpNoThrow(AppOpsManager.OP_VIBRATE, vib.uid, vib.opPkg);
                    AppOpsManager.OP_VIBRATE, vib.uid, vib.opPkg);
            }
        } catch (RemoteException e) {
            Slog.e(TAG, "Failed to get appop mode for vibration!", e);
            mode = AppOpsManager.MODE_IGNORED;
        }
        }
        return mode;
        return mode;
    }
    }
@@ -741,11 +733,8 @@ public class VibratorService extends IVibratorService.Stub
        Trace.traceBegin(Trace.TRACE_TAG_VIBRATOR, "reportFinishVibrationLocked");
        Trace.traceBegin(Trace.TRACE_TAG_VIBRATOR, "reportFinishVibrationLocked");
        try {
        try {
            if (mCurrentVibration != null) {
            if (mCurrentVibration != null) {
                try {
                mAppOps.finishOp(AppOpsManager.OP_VIBRATE, mCurrentVibration.uid,
                    mAppOpsService.finishOperation(AppOpsManager.getToken(mAppOpsService),
                            AppOpsManager.OP_VIBRATE, mCurrentVibration.uid,
                        mCurrentVibration.opPkg);
                        mCurrentVibration.opPkg);
                } catch (RemoteException e) { }
                unlinkVibration(mCurrentVibration);
                unlinkVibration(mCurrentVibration);
                mCurrentVibration = null;
                mCurrentVibration = null;
            }
            }
Loading