blob: f1100b216f97b15d06bf278bc8ecba9406d87f06 [file] [log] [blame]
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001/*
2 * Copyright (C) 2007 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.stk;
18
Takanori Nakano48544352016-12-02 18:32:59 +090019import android.app.ActionBar;
Wink Savillee68857d2014-10-17 15:23:05 -070020import android.app.ListActivity;
21import android.content.Context;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080022import android.content.Intent;
23import android.os.Bundle;
Wink Savillee68857d2014-10-17 15:23:05 -070024import android.view.View;
25import android.view.KeyEvent;
Wink Savillee68857d2014-10-17 15:23:05 -070026import android.widget.ImageView;
27import android.widget.ListView;
28import android.widget.TextView;
29import android.graphics.Bitmap;
30import android.graphics.BitmapFactory;
31
32import com.android.internal.telephony.cat.Item;
33import com.android.internal.telephony.cat.Menu;
34import com.android.internal.telephony.cat.CatLog;
35import com.android.internal.telephony.PhoneConstants;
36
37import android.telephony.TelephonyManager;
38
39import java.util.ArrayList;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080040
41/**
Wink Saville79085fc2009-06-09 10:27:23 -070042 * Launcher class. Serve as the app's MAIN activity, send an intent to the
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080043 * StkAppService and finish.
Wink Saville79085fc2009-06-09 10:27:23 -070044 *
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080045 */
Wink Savillee68857d2014-10-17 15:23:05 -070046public class StkLauncherActivity extends ListActivity {
47 private TextView mTitleTextView = null;
48 private ImageView mTitleIconView = null;
Yoshiaki Naka3a980db2019-10-30 17:11:33 +090049 private static final String LOG_TAG =
50 new Object(){}.getClass().getEnclosingClass().getSimpleName();
Wink Savillee68857d2014-10-17 15:23:05 -070051 private ArrayList<Item> mStkMenuList = null;
52 private int mSingleSimId = -1;
53 private Context mContext = null;
54 private TelephonyManager mTm = null;
55 private Bitmap mBitMap = null;
56 private boolean mAcceptUsersInput = true;
57
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080058 @Override
Wink Savillee68857d2014-10-17 15:23:05 -070059 public void onCreate(Bundle icicle) {
60 super.onCreate(icicle);
61 CatLog.d(LOG_TAG, "onCreate+");
62 mContext = getBaseContext();
63 mTm = (TelephonyManager) mContext.getSystemService(
64 Context.TELEPHONY_SERVICE);
Takanori Nakano48544352016-12-02 18:32:59 +090065
66 ActionBar actionBar = getActionBar();
67 actionBar.setCustomView(R.layout.stk_title);
68 actionBar.setDisplayShowCustomEnabled(true);
69
Legler Wuaeefef52014-10-27 00:57:18 +080070 setContentView(R.layout.stk_menu_list);
71 mTitleTextView = (TextView) findViewById(R.id.title_text);
72 mTitleIconView = (ImageView) findViewById(R.id.title_icon);
73 mTitleTextView.setText(R.string.app_name);
74 mBitMap = BitmapFactory.decodeResource(getResources(),
75 R.drawable.ic_launcher_sim_toolkit);
Wink Savillee68857d2014-10-17 15:23:05 -070076 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080077
Wink Savillee68857d2014-10-17 15:23:05 -070078 @Override
79 protected void onNewIntent(Intent intent) {
80 super.onNewIntent(intent);
81 }
82
83 @Override
84 protected void onListItemClick(ListView l, View v, int position, long id) {
85 super.onListItemClick(l, v, position, id);
86 if (!mAcceptUsersInput) {
87 CatLog.d(LOG_TAG, "mAcceptUsersInput:false");
88 return;
89 }
90 int simCount = TelephonyManager.from(mContext).getSimCount();
91 Item item = getSelectedItem(position);
92 if (item == null) {
93 CatLog.d(LOG_TAG, "Item is null");
94 return;
95 }
96 CatLog.d(LOG_TAG, "launch stk menu id: " + item.id);
Yoshiaki Naka8b960fb2019-10-31 10:44:07 +090097 if (item.id >= 0 && item.id < simCount) {
Wink Savillee68857d2014-10-17 15:23:05 -070098 mAcceptUsersInput = false;
99 launchSTKMainMenu(item.id);
100 }
101 }
102
103 @Override
104 public boolean onKeyDown(int keyCode, KeyEvent event) {
105 CatLog.d(LOG_TAG, "mAcceptUsersInput: " + mAcceptUsersInput);
106 if (!mAcceptUsersInput) {
107 return true;
108 }
109 switch (keyCode) {
110 case KeyEvent.KEYCODE_BACK:
111 CatLog.d(LOG_TAG, "KEYCODE_BACK.");
112 mAcceptUsersInput = false;
113 finish();
114 return true;
115 }
116 return super.onKeyDown(keyCode, event);
117 }
118
119 @Override
120 public void onResume() {
121 super.onResume();
122 CatLog.d(LOG_TAG, "onResume");
123 mAcceptUsersInput = true;
124 int itemSize = addStkMenuListItems();
125 if (itemSize == 0) {
126 CatLog.d(LOG_TAG, "item size = 0 so finish.");
127 finish();
128 } else if (itemSize == 1) {
129 launchSTKMainMenu(mSingleSimId);
130 finish();
131 } else {
132 CatLog.d(LOG_TAG, "resume to show multiple stk list.");
133 }
134 }
135
136 @Override
137 public void onPause() {
138 super.onPause();
139 CatLog.d(LOG_TAG, "onPause");
140 }
141
142 @Override
143 public void onDestroy() {
144 super.onDestroy();
145 CatLog.d(LOG_TAG, "onDestroy");
146 }
147
148 private Item getSelectedItem(int position) {
149 Item item = null;
150 if (mStkMenuList != null) {
151 try {
152 item = mStkMenuList.get(position);
153 } catch (IndexOutOfBoundsException e) {
154 if (StkApp.DBG) {
155 CatLog.d(LOG_TAG, "IOOBE Invalid menu");
156 }
157 } catch (NullPointerException e) {
158 if (StkApp.DBG) {
159 CatLog.d(LOG_TAG, "NPE Invalid menu");
160 }
161 }
162 }
163 return item;
164 }
165
166 private int addStkMenuListItems() {
Takanori Nakano89e5d462016-03-31 20:10:30 +0900167 StkAppService appService = StkAppService.getInstance();
Yoshiaki Naka7153ec52017-10-17 15:08:56 +0900168 if (appService == null) {
169 return 0;
170 }
171
172 String appName = mContext.getResources().getString(R.string.app_name);
Wink Savillee68857d2014-10-17 15:23:05 -0700173 String stkItemName = null;
174 int simCount = TelephonyManager.from(mContext).getSimCount();
175 mStkMenuList = new ArrayList<Item>();
176
177 CatLog.d(LOG_TAG, "simCount: " + simCount);
178 for (int i = 0; i < simCount; i++) {
Yoshiaki Naka7153ec52017-10-17 15:08:56 +0900179 // Check if the card is inserted.
Wink Savillee68857d2014-10-17 15:23:05 -0700180 if (mTm.hasIccCard(i)) {
Yoshiaki Naka7153ec52017-10-17 15:08:56 +0900181 Menu menu = appService.getMainMenu(i);
182 // Check if the card has a main menu.
183 if (menu != null) {
184 CatLog.d(LOG_TAG, "SIM #" + (i + 1) + " is add to menu.");
185 mSingleSimId = i;
186 stkItemName = new StringBuilder(menu.title == null ? appName : menu.title)
187 .append(" ").append(Integer.toString(i + 1)).toString();
Takanori Nakanoc8054ba2016-08-15 19:18:16 +0900188 // Display the default application icon if there is no icon specified by SET-UP
189 // MENU command nor preset.
190 Bitmap icon = mBitMap;
191 if (menu.titleIcon != null) {
192 icon = menu.titleIcon;
193 if (menu.titleIconSelfExplanatory) {
194 stkItemName = null;
195 }
196 }
197 Item item = new Item(i, stkItemName, icon);
Yoshiaki Naka7153ec52017-10-17 15:08:56 +0900198 mStkMenuList.add(item);
199 } else {
200 CatLog.d(LOG_TAG, "SIM #" + (i + 1) + " does not have main menu.");
201 }
Wink Savillee68857d2014-10-17 15:23:05 -0700202 } else {
Yoshiaki Naka7153ec52017-10-17 15:08:56 +0900203 CatLog.d(LOG_TAG, "SIM #" + (i + 1) + " is not inserted.");
Wink Savillee68857d2014-10-17 15:23:05 -0700204 }
205 }
206 if (mStkMenuList != null && mStkMenuList.size() > 0) {
207 if (mStkMenuList.size() > 1) {
208 StkMenuAdapter adapter = new StkMenuAdapter(this,
209 mStkMenuList, false);
210 // Bind menu list to the new adapter.
211 this.setListAdapter(adapter);
212 }
213 return mStkMenuList.size();
214 } else {
215 CatLog.d(LOG_TAG, "No stk menu item add.");
216 return 0;
217 }
218 }
Wink Savillee68857d2014-10-17 15:23:05 -0700219 private void launchSTKMainMenu(int slodId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800220 Bundle args = new Bundle();
Wink Savillee68857d2014-10-17 15:23:05 -0700221 CatLog.d(LOG_TAG, "launchSTKMainMenu.");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800222 args.putInt(StkAppService.OPCODE, StkAppService.OP_LAUNCH_APP);
Yoshiaki Naka8b960fb2019-10-31 10:44:07 +0900223 args.putInt(StkAppService.SLOT_ID, slodId);
Wink Savillee68857d2014-10-17 15:23:05 -0700224 startService(new Intent(this, StkAppService.class)
225 .putExtras(args));
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800226 }
227}