Search in sources :

Example 1 with IAppOpsCallback

use of com.android.internal.app.IAppOpsCallback in project android_frameworks_base by ParanoidAndroid.

the class AppOpsManager method startWatchingMode.

public void startWatchingMode(int op, String packageName, final Callback callback) {
    synchronized (mModeWatchers) {
        IAppOpsCallback cb = mModeWatchers.get(callback);
        if (cb == null) {
            cb = new IAppOpsCallback.Stub() {

                public void opChanged(int op, String packageName) {
                    callback.opChanged(op, packageName);
                }
            };
            mModeWatchers.put(callback, cb);
        }
        try {
            mService.startWatchingMode(op, packageName, cb);
        } catch (RemoteException e) {
        }
    }
}
Also used : IAppOpsCallback(com.android.internal.app.IAppOpsCallback) RemoteException(android.os.RemoteException)

Example 2 with IAppOpsCallback

use of com.android.internal.app.IAppOpsCallback in project platform_frameworks_base by android.

the class AppOpsService method startWatchingMode.

@Override
public void startWatchingMode(int op, String packageName, IAppOpsCallback callback) {
    if (callback == null) {
        return;
    }
    synchronized (this) {
        op = (op != AppOpsManager.OP_NONE) ? AppOpsManager.opToSwitch(op) : op;
        Callback cb = mModeWatchers.get(callback.asBinder());
        if (cb == null) {
            cb = new Callback(callback);
            mModeWatchers.put(callback.asBinder(), cb);
        }
        if (op != AppOpsManager.OP_NONE) {
            ArrayList<Callback> cbs = mOpModeWatchers.get(op);
            if (cbs == null) {
                cbs = new ArrayList<Callback>();
                mOpModeWatchers.put(op, cbs);
            }
            cbs.add(cb);
        }
        if (packageName != null) {
            ArrayList<Callback> cbs = mPackageModeWatchers.get(packageName);
            if (cbs == null) {
                cbs = new ArrayList<Callback>();
                mPackageModeWatchers.put(packageName, cbs);
            }
            cbs.add(cb);
        }
    }
}
Also used : IAppOpsCallback(com.android.internal.app.IAppOpsCallback)

Example 3 with IAppOpsCallback

use of com.android.internal.app.IAppOpsCallback in project platform_frameworks_base by android.

the class AppOpsService method stopWatchingMode.

@Override
public void stopWatchingMode(IAppOpsCallback callback) {
    if (callback == null) {
        return;
    }
    synchronized (this) {
        Callback cb = mModeWatchers.remove(callback.asBinder());
        if (cb != null) {
            cb.unlinkToDeath();
            for (int i = mOpModeWatchers.size() - 1; i >= 0; i--) {
                ArrayList<Callback> cbs = mOpModeWatchers.valueAt(i);
                cbs.remove(cb);
                if (cbs.size() <= 0) {
                    mOpModeWatchers.removeAt(i);
                }
            }
            for (int i = mPackageModeWatchers.size() - 1; i >= 0; i--) {
                ArrayList<Callback> cbs = mPackageModeWatchers.valueAt(i);
                cbs.remove(cb);
                if (cbs.size() <= 0) {
                    mPackageModeWatchers.removeAt(i);
                }
            }
        }
    }
}
Also used : IAppOpsCallback(com.android.internal.app.IAppOpsCallback)

Example 4 with IAppOpsCallback

use of com.android.internal.app.IAppOpsCallback in project platform_frameworks_base by android.

the class AppOpsManager method startWatchingMode.

/**
     * Monitor for changes to the operating mode for the given op in the given app package.
     * @param op The operation to monitor, one of OP_*.
     * @param packageName The name of the application to monitor.
     * @param callback Where to report changes.
     * @hide
     */
public void startWatchingMode(int op, String packageName, final OnOpChangedListener callback) {
    synchronized (mModeWatchers) {
        IAppOpsCallback cb = mModeWatchers.get(callback);
        if (cb == null) {
            cb = new IAppOpsCallback.Stub() {

                public void opChanged(int op, int uid, String packageName) {
                    if (callback instanceof OnOpChangedInternalListener) {
                        ((OnOpChangedInternalListener) callback).onOpChanged(op, packageName);
                    }
                    if (sOpToString[op] != null) {
                        callback.onOpChanged(sOpToString[op], packageName);
                    }
                }
            };
            mModeWatchers.put(callback, cb);
        }
        try {
            mService.startWatchingMode(op, packageName, cb);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
}
Also used : IAppOpsCallback(com.android.internal.app.IAppOpsCallback) RemoteException(android.os.RemoteException)

Example 5 with IAppOpsCallback

use of com.android.internal.app.IAppOpsCallback in project android_frameworks_base by DirtyUnicorns.

the class AppOpsService method stopWatchingMode.

@Override
public void stopWatchingMode(IAppOpsCallback callback) {
    if (callback == null) {
        return;
    }
    synchronized (this) {
        Callback cb = mModeWatchers.remove(callback.asBinder());
        if (cb != null) {
            cb.unlinkToDeath();
            for (int i = mOpModeWatchers.size() - 1; i >= 0; i--) {
                ArrayList<Callback> cbs = mOpModeWatchers.valueAt(i);
                cbs.remove(cb);
                if (cbs.size() <= 0) {
                    mOpModeWatchers.removeAt(i);
                }
            }
            for (int i = mPackageModeWatchers.size() - 1; i >= 0; i--) {
                ArrayList<Callback> cbs = mPackageModeWatchers.valueAt(i);
                cbs.remove(cb);
                if (cbs.size() <= 0) {
                    mPackageModeWatchers.removeAt(i);
                }
            }
        }
    }
}
Also used : IAppOpsCallback(com.android.internal.app.IAppOpsCallback)

Aggregations

IAppOpsCallback (com.android.internal.app.IAppOpsCallback)18 RemoteException (android.os.RemoteException)6 ArrayList (java.util.ArrayList)1