1 /* Copyright 2016 Braden Farmer
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 package com.farmerbb.taskbar.activity;
18 import android.annotation.SuppressLint;
19 import android.annotation.TargetApi;
20 import android.app.Activity;
21 import android.app.AlertDialog;
22 import android.app.admin.DevicePolicyManager;
23 import android.content.ActivityNotFoundException;
24 import android.content.ComponentName;
25 import android.content.Intent;
26 import android.content.SharedPreferences;
27 import android.net.Uri;
28 import android.os.Build;
29 import android.os.Bundle;
30 import android.os.Handler;
31 import android.os.UserManager;
32 import android.provider.Settings;
33 import android.view.View;
35 import com.farmerbb.taskbar.R;
36 import com.farmerbb.taskbar.receiver.LockDeviceReceiver;
37 import com.farmerbb.taskbar.util.ApplicationType;
38 import com.farmerbb.taskbar.util.FreeformHackHelper;
39 import com.farmerbb.taskbar.util.U;
41 public class DummyActivity extends Activity {
43 boolean shouldFinish = false;
46 protected void onCreate(Bundle savedInstanceState) {
47 super.onCreate(savedInstanceState);
48 setContentView(new View(this));
51 @SuppressLint("RestrictedApi")
52 @TargetApi(Build.VERSION_CODES.N)
54 protected void onResume() {
61 if(getIntent().hasExtra("uninstall")) {
62 UserManager userManager = (UserManager) getSystemService(USER_SERVICE);
64 Intent intent = new Intent(Intent.ACTION_DELETE, Uri.parse("package:" + getIntent().getStringExtra("uninstall")));
65 intent.putExtra(Intent.EXTRA_USER, userManager.getUserForSerialNumber(getIntent().getLongExtra("user_id", 0)));
68 startActivity(intent);
69 } catch (ActivityNotFoundException e) { /* Gracefully fail */ }
70 } else if(getIntent().hasExtra("device_admin")) {
71 AlertDialog.Builder builder = new AlertDialog.Builder(U.wrapContext(this));
72 builder.setTitle(R.string.permission_dialog_title)
73 .setMessage(R.string.device_admin_disclosure)
74 .setNegativeButton(R.string.action_cancel, (dialog, which) -> new Handler().post(this::finish))
75 .setPositiveButton(R.string.action_activate, (dialog, which) -> {
76 Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
77 intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, new ComponentName(this, LockDeviceReceiver.class));
78 intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, getString(R.string.device_admin_description));
80 SharedPreferences pref = U.getSharedPreferences(this);
81 if(pref.getBoolean("disable_animations", false))
82 intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
84 U.launchApp(this, () -> {
86 startActivity(intent, U.getActivityOptionsBundle(this, ApplicationType.APPLICATION));
87 } catch (ActivityNotFoundException e) {
88 U.showToast(this, R.string.lock_device_not_supported);
95 AlertDialog dialog = builder.create();
97 dialog.setCancelable(false);
98 } else if(getIntent().hasExtra("accessibility")) {
99 AlertDialog.Builder builder = new AlertDialog.Builder(U.wrapContext(this));
100 builder.setTitle(R.string.permission_dialog_title)
101 .setMessage(R.string.enable_accessibility)
102 .setNegativeButton(R.string.action_cancel, (dialog, which) -> new Handler().post(this::finish))
103 .setPositiveButton(R.string.action_activate, (dialog, which) -> {
104 Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
106 SharedPreferences pref = U.getSharedPreferences(this);
107 if(pref.getBoolean("disable_animations", false))
108 intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
110 U.launchApp(this, () -> {
112 startActivity(intent, U.getActivityOptionsBundle(this, ApplicationType.APPLICATION));
113 U.showToastLong(this, R.string.usage_stats_message);
114 } catch (ActivityNotFoundException e) {
115 U.showToast(this, R.string.lock_device_not_supported);
122 AlertDialog dialog = builder.create();
124 dialog.setCancelable(false);
125 } else if(getIntent().hasExtra("start_freeform_hack")) {
126 SharedPreferences pref = U.getSharedPreferences(this);
127 if(U.hasFreeformSupport(this)
128 && pref.getBoolean("freeform_hack", false)
129 && isInMultiWindowMode()
130 && !FreeformHackHelper.getInstance().isFreeformHackActive()) {
131 U.startFreeformHack(this);
135 } else if(getIntent().hasExtra("show_permission_dialog"))
136 U.showPermissionDialog(U.wrapContext(this), null, this::finish);
137 else if(getIntent().hasExtra("show_recent_apps_dialog"))
138 U.showRecentAppsDialog(U.wrapContext(this), null, this::finish);