blob: 449ed8c3bcdba115024886e3985f597cfc31388c [file] [log] [blame]
Jason Monke8f8be72018-01-21 10:10:35 -05001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15package com.android.systemui;
16
Philip P. Moltmann66ce2382018-10-09 13:46:11 -070017import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Jason Monkb14dde072018-05-25 15:13:16 -040018
Jason Monke8f8be72018-01-21 10:10:35 -050019import android.app.Activity;
20import android.app.AlertDialog;
21import android.app.slice.SliceManager;
22import android.app.slice.SliceProvider;
23import android.content.DialogInterface;
24import android.content.DialogInterface.OnClickListener;
25import android.content.DialogInterface.OnDismissListener;
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -070026import android.content.pm.PackageItemInfo;
Jason Monke8f8be72018-01-21 10:10:35 -050027import android.content.pm.PackageManager;
28import android.content.pm.PackageManager.NameNotFoundException;
29import android.net.Uri;
30import android.os.Bundle;
Jason Monk3cc74c52018-04-09 08:10:59 -040031import android.text.BidiFormatter;
Jason Monke8f8be72018-01-21 10:10:35 -050032import android.util.Log;
33import android.widget.CheckBox;
34import android.widget.TextView;
35
36public class SlicePermissionActivity extends Activity implements OnClickListener,
37 OnDismissListener {
38
39 private static final String TAG = "SlicePermissionActivity";
40
41 private CheckBox mAllCheckbox;
42
43 private Uri mUri;
44 private String mCallingPkg;
45 private String mProviderPkg;
46
47 @Override
48 protected void onCreate(Bundle savedInstanceState) {
49 super.onCreate(savedInstanceState);
50
51 mUri = getIntent().getParcelableExtra(SliceProvider.EXTRA_BIND_URI);
52 mCallingPkg = getIntent().getStringExtra(SliceProvider.EXTRA_PKG);
53 mProviderPkg = getIntent().getStringExtra(SliceProvider.EXTRA_PROVIDER_PKG);
54
55 try {
56 PackageManager pm = getPackageManager();
Philip P. Moltmanna6f5c702018-04-23 09:09:16 -070057 CharSequence app1 = BidiFormatter.getInstance().unicodeWrap(pm.getApplicationInfo(
58 mCallingPkg, 0).loadSafeLabel(pm, PackageItemInfo.DEFAULT_MAX_LABEL_SIZE_PX,
59 PackageItemInfo.SAFE_LABEL_FLAG_TRIM
60 | PackageItemInfo.SAFE_LABEL_FLAG_FIRST_LINE).toString());
61 CharSequence app2 = BidiFormatter.getInstance().unicodeWrap(pm.getApplicationInfo(
62 mProviderPkg, 0).loadSafeLabel(pm, PackageItemInfo.DEFAULT_MAX_LABEL_SIZE_PX,
63 PackageItemInfo.SAFE_LABEL_FLAG_TRIM
64 | PackageItemInfo.SAFE_LABEL_FLAG_FIRST_LINE).toString());
Jason Monke8f8be72018-01-21 10:10:35 -050065 AlertDialog dialog = new AlertDialog.Builder(this)
66 .setTitle(getString(R.string.slice_permission_title, app1, app2))
67 .setView(R.layout.slice_permission_request)
68 .setNegativeButton(R.string.slice_permission_deny, this)
69 .setPositiveButton(R.string.slice_permission_allow, this)
70 .setOnDismissListener(this)
Jason Monkb14dde072018-05-25 15:13:16 -040071 .create();
Philip P. Moltmann66ce2382018-10-09 13:46:11 -070072 dialog.getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
Jason Monkb14dde072018-05-25 15:13:16 -040073 dialog.show();
Jason Monke8f8be72018-01-21 10:10:35 -050074 TextView t1 = dialog.getWindow().getDecorView().findViewById(R.id.text1);
75 t1.setText(getString(R.string.slice_permission_text_1, app2));
76 TextView t2 = dialog.getWindow().getDecorView().findViewById(R.id.text2);
77 t2.setText(getString(R.string.slice_permission_text_2, app2));
78 mAllCheckbox = dialog.getWindow().getDecorView().findViewById(
79 R.id.slice_permission_checkbox);
80 mAllCheckbox.setText(getString(R.string.slice_permission_checkbox, app1));
81 } catch (NameNotFoundException e) {
82 Log.e(TAG, "Couldn't find package", e);
83 finish();
84 }
85 }
86
87 @Override
88 public void onClick(DialogInterface dialog, int which) {
89 if (which == DialogInterface.BUTTON_POSITIVE) {
90 getSystemService(SliceManager.class).grantPermissionFromUser(mUri, mCallingPkg,
91 mAllCheckbox.isChecked());
92 }
93 finish();
94 }
95
96 @Override
97 public void onDismiss(DialogInterface dialog) {
98 finish();
99 }
100}