blob: e732152a07532f9f63c91d2cd6d3c6070d5a0deb [file] [log] [blame]
Legler Wuaeefef52014-10-27 00:57:18 +08001/*
2 * Copyright (C) 2014 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
19import android.app.Activity;
20import android.content.Context;
21import android.content.Intent;
22import android.os.Bundle;
Legler Wuaeefef52014-10-27 00:57:18 +080023
24import com.android.internal.telephony.cat.CatLog;
Legler Wuaeefef52014-10-27 00:57:18 +080025
26import android.telephony.TelephonyManager;
27
28import android.view.Gravity;
arunvodduaa8d8c32022-06-27 16:26:07 +000029import android.view.WindowManager;
Legler Wuaeefef52014-10-27 00:57:18 +080030import android.widget.Toast;
31
32/**
33 * Launcher class. Serve as the app's MAIN activity, send an intent to the
34 * StkAppService and finish.
35 *
36 */
37 public class StkMain extends Activity {
Yoshiaki Naka3a980db2019-10-30 17:11:33 +090038 private static final String LOG_TAG =
39 new Object(){}.getClass().getEnclosingClass().getSimpleName();
Legler Wuaeefef52014-10-27 00:57:18 +080040 private int mSingleSimId = -1;
41 private Context mContext = null;
42 private TelephonyManager mTm = null;
43 private static final String PACKAGE_NAME = "com.android.stk";
44 private static final String STK_LAUNCHER_ACTIVITY_NAME = PACKAGE_NAME + ".StkLauncherActivity";
45
46 @Override
47 public void onCreate(Bundle icicle) {
48 super.onCreate(icicle);
arunvodduaa8d8c32022-06-27 16:26:07 +000049 getWindow().addSystemFlags(
50 WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
Legler Wuaeefef52014-10-27 00:57:18 +080051 CatLog.d(LOG_TAG, "onCreate+");
52 mContext = getBaseContext();
53 mTm = (TelephonyManager) mContext.getSystemService(
54 Context.TELEPHONY_SERVICE);
55 //Check if needs to show the meun list.
56 if (isShowSTKListMenu()) {
57 Intent newIntent = new Intent(Intent.ACTION_VIEW);
58 newIntent.setClassName(PACKAGE_NAME, STK_LAUNCHER_ACTIVITY_NAME);
59 startActivity(newIntent);
60 } else {
61 //launch stk menu activity for the SIM.
62 if (mSingleSimId < 0) {
63 showTextToast(mContext, R.string.no_sim_card_inserted);
64 } else {
65 launchSTKMainMenu(mSingleSimId);
66 }
67 }
68 finish();
69 }
70
71 private boolean isShowSTKListMenu() {
72 int simCount = TelephonyManager.from(mContext).getSimCount();
73 int simInsertedCount = 0;
74 int insertedSlotId = -1;
75
76 CatLog.d(LOG_TAG, "simCount: " + simCount);
77 for (int i = 0; i < simCount; i++) {
78 //Check if the card is inserted.
79 if (mTm.hasIccCard(i)) {
80 CatLog.d(LOG_TAG, "SIM " + i + " is inserted.");
81 mSingleSimId = i;
82 simInsertedCount++;
83 } else {
84 CatLog.d(LOG_TAG, "SIM " + i + " is not inserted.");
85 }
86 }
87 if (simInsertedCount > 1) {
88 return true;
89 } else {
90 //No card or only one card.
91 CatLog.d(LOG_TAG, "do not show stk list menu.");
92 return false;
93 }
94 }
95
96 private void launchSTKMainMenu(int slotId) {
97 Bundle args = new Bundle();
98 CatLog.d(LOG_TAG, "launchSTKMainMenu.");
99 args.putInt(StkAppService.OPCODE, StkAppService.OP_LAUNCH_APP);
Yoshiaki Naka8b960fb2019-10-31 10:44:07 +0900100 args.putInt(StkAppService.SLOT_ID, slotId);
Legler Wuaeefef52014-10-27 00:57:18 +0800101 startService(new Intent(this, StkAppService.class)
102 .putExtras(args));
103 }
104
105 private void showTextToast(Context context, int resId) {
106 Toast toast = Toast.makeText(context, resId, Toast.LENGTH_LONG);
107 toast.setGravity(Gravity.BOTTOM, 0, 0);
108 toast.show();
109 }
110}