1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.egg; 18 19 import android.app.Activity; 20 import android.content.ComponentName; 21 import android.content.pm.PackageManager; 22 import android.provider.Settings; 23 import android.util.Log; 24 import android.widget.Toast; 25 26 import com.android.egg.neko.NekoControlsService; 27 import com.android.egg.widget.PaintChipsActivity; 28 import com.android.egg.widget.PaintChipsWidget; 29 30 /** 31 * Launched from the PlatLogoActivity. Enables everything else in this easter egg. 32 */ 33 public class ComponentActivationActivity extends Activity { 34 private static final String TAG = "EasterEgg"; 35 36 private static final String S_EGG_UNLOCK_SETTING = "egg_mode_s"; 37 toastUp(String s)38 private void toastUp(String s) { 39 Toast toast = Toast.makeText(this, s, Toast.LENGTH_SHORT); 40 toast.show(); 41 } 42 43 @Override onStart()44 public void onStart() { 45 super.onStart(); 46 47 final PackageManager pm = getPackageManager(); 48 final ComponentName[] cns = new ComponentName[] { 49 new ComponentName(this, NekoControlsService.class), 50 new ComponentName(this, PaintChipsActivity.class), 51 new ComponentName(this, PaintChipsWidget.class) 52 }; 53 final long unlockValue = Settings.System.getLong(getContentResolver(), 54 S_EGG_UNLOCK_SETTING, 0); 55 for (ComponentName cn : cns) { 56 final boolean componentEnabled = pm.getComponentEnabledSetting(cn) 57 == PackageManager.COMPONENT_ENABLED_STATE_ENABLED; 58 if (unlockValue == 0) { 59 if (componentEnabled) { 60 Log.v(TAG, "Disabling component: " + cn); 61 pm.setComponentEnabledSetting(cn, 62 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 63 PackageManager.DONT_KILL_APP); 64 //toastUp("\uD83D\uDEAB"); 65 } else { 66 Log.v(TAG, "Already disabled: " + cn); 67 } 68 } else { 69 if (!componentEnabled) { 70 Log.v(TAG, "Enabling component: " + cn); 71 pm.setComponentEnabledSetting(cn, 72 PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 73 PackageManager.DONT_KILL_APP); 74 //toastUp("\uD83D\uDC31"); 75 } else { 76 Log.v(TAG, "Already enabled: " + cn); 77 } 78 } 79 } 80 81 finish(); 82 } 83 } 84