blob: 5820b5a758942726c0b180e483d2324ff1a42128 [file] [log] [blame]
Aurimas Liutikas88c7ff12023-08-10 12:42:26 -07001/*
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
17package com.android.egg;
18
19import android.app.Activity;
20import android.content.ComponentName;
21import android.content.pm.PackageManager;
22import android.provider.Settings;
23import android.util.Log;
24import android.widget.Toast;
25
26import com.android.egg.neko.NekoControlsService;
27import com.android.egg.widget.PaintChipsActivity;
28import com.android.egg.widget.PaintChipsWidget;
29
30/**
31 * Launched from the PlatLogoActivity. Enables everything else in this easter egg.
32 */
33public 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
38 private void toastUp(String s) {
39 Toast toast = Toast.makeText(this, s, Toast.LENGTH_SHORT);
40 toast.show();
41 }
42
43 @Override
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}