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

Commit c2293025 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

App ops: track system windows, monitoring changes.

Change-Id: I273e82bdad66ada3bf0f7ec9176bc304b9ee1ee8
parent 0984780b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -166,6 +166,7 @@ LOCAL_SRC_FILES += \
	core/java/android/speech/IRecognitionService.aidl \
	core/java/android/speech/tts/ITextToSpeechCallback.aidl \
	core/java/android/speech/tts/ITextToSpeechService.aidl \
	core/java/com/android/internal/app/IAppOpsCallback.aidl \
	core/java/com/android/internal/app/IAppOpsService.aidl \
	core/java/com/android/internal/app/IBatteryStats.aidl \
	core/java/com/android/internal/app/IUsageStats.aidl \
+44 −2
Original line number Diff line number Diff line
@@ -16,10 +16,11 @@

package android.app;

import android.Manifest;
import com.android.internal.app.IAppOpsService;
import com.android.internal.app.IAppOpsCallback;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.content.Context;
@@ -32,6 +33,8 @@ import android.os.RemoteException;
public class AppOpsManager {
    final Context mContext;
    final IAppOpsService mService;
    final HashMap<Callback, IAppOpsCallback> mModeWatchers
            = new HashMap<Callback, IAppOpsCallback>();

    public static final int MODE_ALLOWED = 0;
    public static final int MODE_IGNORED = 1;
@@ -62,8 +65,9 @@ public class AppOpsManager {
    public static final int OP_READ_ICC_SMS = 21;
    public static final int OP_WRITE_ICC_SMS = 22;
    public static final int OP_WRITE_SETTINGS = 23;
    public static final int OP_SYSTEM_ALERT_WINDOW = 24;
    /** @hide */
    public static final int _NUM_OP = 24;
    public static final int _NUM_OP = 25;

    /**
     * This maps each operation to the operation that serves as the
@@ -98,6 +102,7 @@ public class AppOpsManager {
            OP_READ_SMS,
            OP_WRITE_SMS,
            OP_WRITE_SETTINGS,
            OP_SYSTEM_ALERT_WINDOW,
    };

    /**
@@ -129,6 +134,7 @@ public class AppOpsManager {
            "READ_ICC_SMS",
            "WRITE_ICC_SMS",
            "WRITE_SETTINGS",
            "SYSTEM_ALERT_WINDOW",
    };

    /**
@@ -160,6 +166,7 @@ public class AppOpsManager {
            android.Manifest.permission.READ_SMS,
            android.Manifest.permission.WRITE_SMS,
            android.Manifest.permission.WRITE_SETTINGS,
            android.Manifest.permission.SYSTEM_ALERT_WINDOW,
    };

    public static int opToSwitch(int op) {
@@ -167,6 +174,7 @@ public class AppOpsManager {
    }

    public static String opToName(int op) {
        if (op == OP_NONE) return "NONE";
        return op < sOpNames.length ? sOpNames[op] : ("Unknown(" + op + ")");
    }

@@ -305,6 +313,10 @@ public class AppOpsManager {
        };
    }

    public interface Callback {
        public void opChanged(int op, String packageName);
    }

    public AppOpsManager(Context context, IAppOpsService service) {
        mContext = context;
        mService = service;
@@ -333,6 +345,36 @@ public class AppOpsManager {
        }
    }

    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) {
            }
        }
    }

    public void stopWatchingMode(Callback callback) {
        synchronized (mModeWatchers) {
            IAppOpsCallback cb = mModeWatchers.get(callback);
            if (cb != null) {
                try {
                    mService.stopWatchingMode(cb);
                } catch (RemoteException e) {
                }
            }
        }
    }

    public int checkOp(int op, int uid, String packageName) {
        try {
            int mode = mService.checkOperation(op, uid, packageName);
+8 −0
Original line number Diff line number Diff line
@@ -139,6 +139,7 @@ public final class ViewRootImpl implements ViewParent,

    final IWindowSession mWindowSession;
    final Display mDisplay;
    final String mBasePackageName;

    long mLastTrackballTime = 0;
    final TrackballAxis mTrackballAxisX = new TrackballAxis();
@@ -355,6 +356,7 @@ public final class ViewRootImpl implements ViewParent,
        // allow the spawning of threads.
        mWindowSession = WindowManagerGlobal.getWindowSession(context.getMainLooper());
        mDisplay = display;
        mBasePackageName = context.getBasePackageName();

        CompatibilityInfoHolder cih = display.getCompatibilityInfo();
        mCompatibilityInfo = cih != null ? cih : new CompatibilityInfoHolder();
@@ -477,6 +479,9 @@ public final class ViewRootImpl implements ViewParent,
                mViewLayoutDirectionInitial = mView.getRawLayoutDirection();
                mFallbackEventHandler.setView(view);
                mWindowAttributes.copyFrom(attrs);
                if (mWindowAttributes.packageName == null) {
                    mWindowAttributes.packageName = mBasePackageName;
                }
                attrs = mWindowAttributes;
                // Keep track of the actual window flags supplied by the client.
                mClientWindowLayoutFlags = attrs.flags;
@@ -774,6 +779,9 @@ public final class ViewRootImpl implements ViewParent,
            attrs.systemUiVisibility = mWindowAttributes.systemUiVisibility;
            attrs.subtreeSystemUiVisibility = mWindowAttributes.subtreeSystemUiVisibility;
            mWindowAttributesChangesFlag = mWindowAttributes.copyFrom(attrs);
            if (mWindowAttributes.packageName == null) {
                mWindowAttributes.packageName = mBasePackageName;
            }
            mWindowAttributes.flags |= compatibleWindowFlag;

            applyKeepScreenOnFlag(mWindowAttributes);
+4 −2
Original line number Diff line number Diff line
@@ -461,12 +461,14 @@ public interface WindowManagerPolicy {
     * Check permissions when adding a window.
     * 
     * @param attrs The window's LayoutParams.
     * @param outAppOp First element will be filled with the app op corresponding to
     *                 this window, or OP_NONE.
     *  
     * @return {@link WindowManagerGlobal#ADD_OKAY} if the add can proceed;
     *      else an error code, usually
     *      {@link WindowManagerGlobal#ADD_PERMISSION_DENIED}, to abort the add.
     */
    public int checkAddPermission(WindowManager.LayoutParams attrs);
    public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp);

    /**
     * Check permissions when adding a window.
+21 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013 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.internal.app;

oneway interface IAppOpsCallback {
    void opChanged(int op, String packageName);
}
Loading