OSDN Git Service

Add MIPS support
[android-x86/external-koush-Superuser.git] / Superuser / src / com / koushikdutta / superuser / NotifyActivity.java
1 /*
2  * Copyright (C) 2013 Koushik Dutta (@koush)
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.koushikdutta.superuser;
18
19 import com.koushikdutta.superuser.util.Settings;
20
21 import android.app.Activity;
22 import android.content.Intent;
23 import android.content.pm.PackageInfo;
24 import android.content.pm.PackageManager;
25 import android.os.Bundle;
26 import android.view.View;
27 import android.view.View.OnClickListener;
28 import android.widget.ImageView;
29 import android.widget.TextView;
30
31 public class NotifyActivity extends Activity {
32     @Override
33     protected void onCreate(Bundle savedInstanceState) {
34         Settings.applyDarkThemeSetting(this, R.style.RequestThemeDark);
35         super.onCreate(savedInstanceState);
36         
37         setContentView(R.layout.notify);
38         
39         Intent intent = getIntent();
40         if (intent == null) {
41             finish();
42             return;
43         }
44         int callerUid = intent.getIntExtra("caller_uid", -1);
45         if (callerUid == -1) {
46             finish();
47             return;
48         }
49         
50         final View packageInfo = findViewById(R.id.packageinfo);
51         final PackageManager pm = getPackageManager();
52         String[] pkgs = pm.getPackagesForUid(callerUid);
53         TextView unknown = (TextView)findViewById(R.id.unknown);
54         unknown.setText(getString(R.string.unknown_uid, callerUid));
55
56         if (pkgs != null && pkgs.length > 0) {
57             for (String pkg: pkgs) {
58                 try {
59                     PackageInfo pi = pm.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS);
60                     ((TextView)findViewById(R.id.request)).setText(getString(R.string.application_request, pi.applicationInfo.loadLabel(pm)));
61                     ImageView icon = (ImageView)packageInfo.findViewById(R.id.image);
62                     icon.setImageDrawable(pi.applicationInfo.loadIcon(pm));
63                     ((TextView)packageInfo.findViewById(R.id.title)).setText(pi.applicationInfo.loadLabel(pm));
64                     
65                     ((TextView)findViewById(R.id.app_header)).setText(pi.applicationInfo.loadLabel(pm));
66                     ((TextView)findViewById(R.id.package_header)).setText(pi.packageName);
67                     
68                     // could display them all, but screw it...
69                     // maybe a better ux for this later
70                     break;
71                 }
72                 catch (Exception ex) {
73                 }
74             }
75             findViewById(R.id.unknown).setVisibility(View.GONE);
76         }
77         
78         findViewById(R.id.ok).setOnClickListener(new OnClickListener() {
79             @Override
80             public void onClick(View v) {
81                 finish();
82             }
83         });
84     }
85 }