Commit 187a3cba authored by Romain Hunault's avatar Romain Hunault

Merge remote-tracking branch 'origin/lineage-15.1' into v1-oreo

parents f0580739 e76568f9
Pipeline #3297 passed with stage
in 2 minutes and 41 seconds
......@@ -18,6 +18,8 @@ package com.android.settings.development;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.UserManager;
import android.provider.Settings;
import com.android.settingslib.core.lifecycle.Lifecycle;
......@@ -53,6 +55,17 @@ public class DevelopmentSettingsEnabler implements LifecycleObserver, OnResume {
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
}
public static boolean isDevelopmentSettingsEnabled(Context context) {
final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
final boolean settingEnabled = Settings.Global.getInt(context.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED,
Build.TYPE.equals("eng") ? 1 : 0) != 0;
final boolean hasRestriction = um.hasUserRestriction(
UserManager.DISALLOW_DEBUGGING_FEATURES);
final boolean isAdminOrDemo = um.isAdminUser() || um.isDemoUser();
return isAdminOrDemo && !hasRestriction && settingEnabled;
}
private void updateEnabledState() {
mLastEnabledState = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
......
......@@ -16,20 +16,29 @@
package com.android.settings.qstile;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.provider.Settings;
import android.service.quicksettings.Tile;
import android.service.quicksettings.TileService;
import android.util.EventLog;
import android.util.Log;
import android.view.IWindowManager;
import android.view.ThreadedRenderer;
import android.view.View;
import android.view.WindowManagerGlobal;
import com.android.internal.app.LocalePicker;
import com.android.internal.statusbar.IStatusBarService;
import com.android.settings.development.DevelopmentSettingsEnabler;
import com.android.settings.development.DevelopmentSettings;
public abstract class DevelopmentTiles extends TileService {
private static final String TAG = "DevelopmentTiles";
protected abstract boolean isEnabled();
......@@ -42,7 +51,33 @@ public abstract class DevelopmentTiles extends TileService {
}
public void refresh() {
getQsTile().setState(isEnabled() ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
final int state;
if (!DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(this)) {
// Reset to disabled state if dev option is off.
if (isEnabled()) {
setIsEnabled(false);
new DevelopmentSettings.SystemPropPoker().execute();
}
final ComponentName cn = new ComponentName(getPackageName(), getClass().getName());
try {
getPackageManager().setComponentEnabledSetting(
cn, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
final IStatusBarService statusBarService = IStatusBarService.Stub.asInterface(
ServiceManager.checkService(Context.STATUS_BAR_SERVICE));
if (statusBarService != null) {
EventLog.writeEvent(0x534e4554, "117770924"); // SaftyNet
statusBarService.remTile(cn);
}
} catch (RemoteException e) {
Log.e(TAG, "Failed to modify QS tile for component " +
cn.toString(), e);
}
state = Tile.STATE_UNAVAILABLE;
} else {
state = isEnabled() ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;
}
getQsTile().setState(state);
getQsTile().updateTile();
}
......@@ -131,4 +166,4 @@ public abstract class DevelopmentTiles extends TileService {
} catch (RemoteException e) { }
}
}
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment