Merge "Use new no overlay flag instead app ops" into oc-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
9cb867d6e3
@@ -29,12 +29,13 @@ import android.support.v7.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.support.v7.preference.Preference.OnPreferenceClickListener;
|
||||
import android.util.Log;
|
||||
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.applications.AppStateAppOpsBridge.PermissionState;
|
||||
import com.android.settings.applications.AppStateOverlayBridge.OverlayState;
|
||||
import com.android.settings.core.TouchOverlayManager;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
||||
|
||||
@@ -60,8 +61,6 @@ public class DrawOverlayDetails extends AppInfoWithHeader implements OnPreferenc
|
||||
private Intent mSettingsIntent;
|
||||
private OverlayState mOverlayState;
|
||||
|
||||
private TouchOverlayManager mTouchOverlayManager;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -69,7 +68,6 @@ public class DrawOverlayDetails extends AppInfoWithHeader implements OnPreferenc
|
||||
Context context = getActivity();
|
||||
mOverlayBridge = new AppStateOverlayBridge(context, mState, null);
|
||||
mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
|
||||
mTouchOverlayManager = new TouchOverlayManager(context);
|
||||
|
||||
// find preferences
|
||||
addPreferencesFromResource(R.xml.app_ops_permissions_details);
|
||||
@@ -92,17 +90,17 @@ public class DrawOverlayDetails extends AppInfoWithHeader implements OnPreferenc
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
mTouchOverlayManager.setOverlayAllowed(false);
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
getActivity().getWindow().addFlags(
|
||||
WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
|
||||
mTouchOverlayManager.setOverlayAllowed(true);
|
||||
public void onPause() {
|
||||
getActivity().getWindow().clearFlags(
|
||||
WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -153,16 +151,6 @@ public class DrawOverlayDetails extends AppInfoWithHeader implements OnPreferenc
|
||||
.getMetricsFeatureProvider().action(getContext(), logCategory, packageName);
|
||||
}
|
||||
|
||||
private boolean canDrawOverlay(String pkgName) {
|
||||
int result = mAppOpsManager.noteOpNoThrow(AppOpsManager.OP_SYSTEM_ALERT_WINDOW,
|
||||
mPackageInfo.applicationInfo.uid, pkgName);
|
||||
if (result == AppOpsManager.MODE_ALLOWED) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean refreshUi() {
|
||||
mOverlayState = mOverlayBridge.getOverlayInfo(mPackageName,
|
||||
|
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.settings.core;
|
||||
|
||||
import android.app.AppOpsManager;
|
||||
import android.content.Context;
|
||||
import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
|
||||
public class TouchOverlayManager {
|
||||
|
||||
private final Context mContext;
|
||||
private final IBinder mToken = new Binder();
|
||||
|
||||
public TouchOverlayManager(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public void setOverlayAllowed(boolean allowed) {
|
||||
final AppOpsManager aom = mContext.getSystemService(AppOpsManager.class);
|
||||
if (aom != null) {
|
||||
aom.setUserRestriction(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, !allowed, mToken);
|
||||
aom.setUserRestriction(AppOpsManager.OP_TOAST_WINDOW, !allowed, mToken);
|
||||
}
|
||||
}
|
||||
}
|
@@ -35,15 +35,13 @@ import android.content.pm.PackageManager;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.provider.SettingsStringUtil;
|
||||
import android.util.Slog;
|
||||
import android.view.WindowManager;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
|
||||
import com.android.internal.app.AlertActivity;
|
||||
import com.android.internal.app.AlertController;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TouchOverlayManager;
|
||||
|
||||
/** @hide */
|
||||
public class NotificationAccessConfirmationActivity extends Activity
|
||||
@@ -54,14 +52,12 @@ public class NotificationAccessConfirmationActivity extends Activity
|
||||
|
||||
private int mUserId;
|
||||
private ComponentName mComponentName;
|
||||
private TouchOverlayManager mTouchOverlayManager;
|
||||
private NotificationManager mNm;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mTouchOverlayManager = new TouchOverlayManager(this);
|
||||
mNm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
mComponentName = getIntent().getParcelableExtra(EXTRA_COMPONENT_NAME);
|
||||
@@ -84,6 +80,20 @@ public class NotificationAccessConfirmationActivity extends Activity
|
||||
.installContent(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
getWindow().addFlags(
|
||||
WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
getWindow().clearFlags(
|
||||
WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
private void onAllow() {
|
||||
String requiredPermission = Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE;
|
||||
try {
|
||||
@@ -121,16 +131,4 @@ public class NotificationAccessConfirmationActivity extends Activity
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mTouchOverlayManager.setOverlayAllowed(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
mTouchOverlayManager.setOverlayAllowed(true);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user