Merge "Clean cherry-pick 'Aggregate network operators by PLMNs instead of Operator names.'"
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 0026311..b6894c5 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -1701,7 +1701,7 @@
return null;
}
- WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
+ WorkSource workSource = getWorkSource(Binder.getCallingUid());
phone.getCellLocation(workSource).fillInNotifierBundle(data);
return data;
}
@@ -1785,7 +1785,7 @@
ArrayList<NeighboringCellInfo> cells = null;
- WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
+ WorkSource workSource = getWorkSource(Binder.getCallingUid());
try {
cells = (ArrayList<NeighboringCellInfo>) sendRequest(
CMD_HANDLE_NEIGHBORING_CELL, workSource,
@@ -1807,7 +1807,7 @@
}
if (DBG_LOC) log("getAllCellInfo: is active user");
- WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
+ WorkSource workSource = getWorkSource(Binder.getCallingUid());
List<CellInfo> cellInfos = new ArrayList<CellInfo>();
for (Phone phone : PhoneFactory.getPhones()) {
final List<CellInfo> info = phone.getAllCellInfo(workSource);
@@ -1819,7 +1819,7 @@
@Override
public void setCellInfoListRate(int rateInMillis) {
enforceModifyPermission();
- WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
+ WorkSource workSource = getWorkSource(Binder.getCallingUid());
mPhone.setCellInfoListRate(rateInMillis, workSource);
}
@@ -4112,14 +4112,9 @@
return null;
}
- private WorkSource getWorkSource(WorkSource workSource, int uid) {
- if (workSource != null) {
- return workSource;
- }
-
+ private WorkSource getWorkSource(int uid) {
String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
- workSource = new WorkSource(uid, packageName);
- return workSource;
+ return new WorkSource(uid, packageName);
}
/**
diff --git a/testapps/TelephonyManagerTestApp/Android.mk b/testapps/TelephonyManagerTestApp/Android.mk
new file mode 100644
index 0000000..290b261
--- /dev/null
+++ b/testapps/TelephonyManagerTestApp/Android.mk
@@ -0,0 +1,19 @@
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+src_dirs := src
+res_dirs := res
+
+LOCAL_SRC_FILES := $(call all-java-files-under, $(src_dirs))
+LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, $(res_dirs))
+
+LOCAL_JAVACFLAGS := -parameters
+
+LOCAL_PACKAGE_NAME := TelephonyManagerTestApp
+LOCAL_PRIVATE_PLATFORM_APIS := true
+
+LOCAL_CERTIFICATE := platform
+LOCAL_MODULE_TAGS := tests
+
+include $(BUILD_PACKAGE)
diff --git a/testapps/TelephonyManagerTestApp/AndroidManifest.xml b/testapps/TelephonyManagerTestApp/AndroidManifest.xml
new file mode 100644
index 0000000..044d0b2
--- /dev/null
+++ b/testapps/TelephonyManagerTestApp/AndroidManifest.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.phone.testapps.telephonymanagertestapp">
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
+ <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
+ <uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
+ <uses-permission android:name="android.permission.READ_SMS"/>
+ <uses-permission android:name="android.permission.SEND_SMS"/>
+ <uses-permission android:name="android.permission.READ_PHONE_NUMBERS"/>
+ <uses-permission android:name="android.permission.CALL_PRIVILEGED"/>
+ <uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE"/>
+
+ android.Manifest.permission.ACCESS_FINE_LOCATION
+ <application android:label="TelephonyManagerTestApp">
+ <activity
+ android:name=".TelephonyManagerTestApp"
+ android:label="TelephonyManagerTestApp">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <action android:name="android.intent.action.SEARCH" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ <meta-data
+ android:name="android.app.searchable"
+ android:resource="@xml/searchable">
+ </meta-data>
+ </activity>
+
+ <activity
+ android:name=".CallingMethodActivity"
+ android:label="CallingMethodActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
+ </application>
+</manifest>
+
diff --git a/testapps/TelephonyManagerTestApp/res/layout/abstract_method_view.xml b/testapps/TelephonyManagerTestApp/res/layout/abstract_method_view.xml
new file mode 100644
index 0000000..fe5e0e4
--- /dev/null
+++ b/testapps/TelephonyManagerTestApp/res/layout/abstract_method_view.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2018 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+ <TextView
+ android:id="@+id/tags"
+ android:layout_width="fill_parent"
+ android:layout_height="20dip"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentRight="true"
+ android:ellipsize="marquee"
+ android:maxLines="1"
+ android:textSize="12sp" />
+
+ <TextView
+ android:id="@+id/method_name"
+ android:layout_width="fill_parent"
+ android:layout_height="30dip"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentRight="true"
+ android:ellipsize="marquee"
+ android:maxLines="2"
+ android:textSize="20sp" />
+
+ <TextView
+ android:id="@+id/parameters"
+ android:layout_width="fill_parent"
+ android:layout_height="match_parent"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentRight="true"
+ android:ellipsize="end"
+ android:maxLines="1"
+ android:textSize="12sp" />
+
+</LinearLayout>
diff --git a/testapps/TelephonyManagerTestApp/res/layout/activity_main.xml b/testapps/TelephonyManagerTestApp/res/layout/activity_main.xml
new file mode 100644
index 0000000..af655db
--- /dev/null
+++ b/testapps/TelephonyManagerTestApp/res/layout/activity_main.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2017 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License
+ -->
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+
+ <ListView
+ android:id="@android:id/list"
+ android:layout_height="match_parent"
+ android:layout_width="match_parent">
+ </ListView>
+</LinearLayout>
diff --git a/testapps/TelephonyManagerTestApp/res/layout/calling_method.xml b/testapps/TelephonyManagerTestApp/res/layout/calling_method.xml
new file mode 100644
index 0000000..668b708
--- /dev/null
+++ b/testapps/TelephonyManagerTestApp/res/layout/calling_method.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2018 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+ <TextView
+ android:id="@+id/sub_id"
+ android:text="subId: "
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:maxLines="1"
+ android:textSize="20sp" />
+
+ <EditText
+ android:id="@+id/sub_id_value"
+ android:text="-1"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:maxLines="1"
+ android:textSize="20sp" />
+ </LinearLayout>
+
+ <TextView
+ android:id="@+id/tags"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentRight="true"
+ android:ellipsize="marquee"
+ android:maxLines="1"
+ android:textSize="15sp" />
+
+ <TextView
+ android:id="@+id/method_name"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:ellipsize="marquee"
+ android:textSize="30sp" />
+
+ <ListView
+ android:id="@android:id/list"
+ android:layout_height="wrap_content"
+ android:layout_width="fill_parent">
+ </ListView>
+
+ <Button
+ android:id="@+id/go_button"
+ android:title="Go"
+ android:text="Go!"
+ android:layout_width="80dip"
+ android:layout_height="50dip">
+ </Button>
+
+ <TextView
+ android:id="@+id/return_value"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:ellipsize="marquee"
+ android:textSize="15sp" />
+</LinearLayout>
diff --git a/testapps/TelephonyManagerTestApp/res/layout/parameter_field.xml b/testapps/TelephonyManagerTestApp/res/layout/parameter_field.xml
new file mode 100644
index 0000000..6bb40fd
--- /dev/null
+++ b/testapps/TelephonyManagerTestApp/res/layout/parameter_field.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2018 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+ <TextView
+ android:id="@+id/field_name"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:maxLines="1"
+ android:textSize="15sp" />
+
+ <!--android:ellipsize="marquee"-->
+ <!--android:layout_alignParentBottom="true"-->
+ <!--android:layout_alignParentRight="true"-->
+
+ <EditText
+ android:id="@+id/field_value"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:maxLines="1"
+ android:textSize="15sp" />
+</LinearLayout>
diff --git a/testapps/TelephonyManagerTestApp/res/menu/search_input.xml b/testapps/TelephonyManagerTestApp/res/menu/search_input.xml
new file mode 100644
index 0000000..261a049
--- /dev/null
+++ b/testapps/TelephonyManagerTestApp/res/menu/search_input.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2018 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License
+ -->
+
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item
+ android:id="@+id/search_input"
+ android:title="Search"
+ android:actionViewClass="android.widget.SearchView"
+ android:showAsAction="collapseActionView|ifRoom"
+ android:imeOptions="actionSearch">
+ </item>
+</menu>
diff --git a/testapps/TelephonyManagerTestApp/res/xml/searchable.xml b/testapps/TelephonyManagerTestApp/res/xml/searchable.xml
new file mode 100644
index 0000000..05cf491
--- /dev/null
+++ b/testapps/TelephonyManagerTestApp/res/xml/searchable.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2018 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License
+ -->
+
+<searchable xmlns:android="http://schemas.android.com/apk/res/android"
+ android:label=".TelephonyManagerTestApp"
+ android:hint="Search...">
+</searchable>
\ No newline at end of file
diff --git a/testapps/TelephonyManagerTestApp/src/com/android/phone/testapps/telephonymanagertestapp/CallingMethodActivity.java b/testapps/TelephonyManagerTestApp/src/com/android/phone/testapps/telephonymanagertestapp/CallingMethodActivity.java
new file mode 100644
index 0000000..aa9dbc0
--- /dev/null
+++ b/testapps/TelephonyManagerTestApp/src/com/android/phone/testapps/telephonymanagertestapp/CallingMethodActivity.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.phone.testapps.telephonymanagertestapp;
+
+import android.app.ListActivity;
+import android.os.Bundle;
+import android.telephony.TelephonyManager;
+import android.util.Log;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.TextView;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+
+/**
+ * Activity to call a specific method of TelephonyManager.
+ */
+public class CallingMethodActivity extends ListActivity {
+ private Class[] mParameterTypes;
+ private Object[] mParameterValues;
+ private Button mGoButton;
+ private Method mMethod;
+ private TextView mReturnValue;
+ private EditText mSubIdField;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.calling_method);
+
+ if (TelephonyManagerTestApp.sCurrentMethod == null) {
+ finish();
+ return;
+ }
+
+ mMethod = TelephonyManagerTestApp.sCurrentMethod;
+
+ mGoButton = findViewById(R.id.go_button);
+ mReturnValue = findViewById(R.id.return_value);
+ mSubIdField = findViewById(R.id.sub_id_value);
+ setListAdapter(new ParameterListAdapter());
+
+ mParameterTypes = mMethod.getParameterTypes();
+ mParameterValues = new Object[mParameterTypes.length];
+
+ String tags = Modifier.toString(mMethod.getModifiers()) + ' '
+ + TelephonyManagerTestApp.getShortTypeName(mMethod.getReturnType().toString());
+ ((TextView) findViewById(R.id.tags)).setText(tags);
+ ((TextView) findViewById(R.id.method_name)).setText(mMethod.getName());
+
+ mGoButton.setOnClickListener((View v) -> executeCallMethod());
+ mReturnValue.setText("Return value: ");
+ }
+
+ private void executeCallMethod() {
+ try {
+ int subId = Integer.parseInt(mSubIdField.getText().toString());
+
+ for (int i = 0; i < mParameterTypes.length; i++) {
+ String text = ((EditText) getListAdapter().getItem(i)).getText().toString();
+ if (mParameterTypes[i] == int.class) {
+ mParameterValues[i] = Integer.parseInt(text);
+ } else if (mParameterTypes[i] == boolean.class) {
+ mParameterValues[i] = Boolean.parseBoolean(text);
+ } else if (mParameterTypes[i] == Long.class) {
+ mParameterValues[i] = Long.parseLong(text);
+ }
+ }
+ Log.d(TelephonyManagerTestApp.TAG, "Invoking method " + mMethod.getName());
+
+ mMethod.setAccessible(true);
+ if (!mMethod.getReturnType().equals(Void.TYPE)) {
+ Object result = mMethod.invoke(new TelephonyManager(this, subId), mParameterValues);
+ if (result instanceof String) {
+ if (((String) result).isEmpty()) {
+ result = "empty string";
+ }
+ }
+ Log.d(TelephonyManagerTestApp.TAG, "result is " + result);
+ mReturnValue.setText("Return value: " + result);
+ } else {
+ mMethod.invoke(new TelephonyManager(this, subId), mParameterValues);
+ mReturnValue.setText("Return value: successfully returned");
+ }
+
+ } catch (Exception exception) {
+ Log.d(TelephonyManagerTestApp.TAG, "NoSuchMethodException " + exception);
+ mReturnValue.setText("NoSuchMethodException " + exception);
+ }
+ }
+
+ private class ParameterListAdapter extends BaseAdapter {
+ ArrayList<EditText> mEditTexts = new ArrayList<>();
+ @Override
+ public int getCount() {
+ return mParameterTypes == null ? 0 : mParameterTypes.length;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup container) {
+ if (mParameterTypes == null || mParameterTypes.length <= position) {
+ return null;
+ }
+
+ if (convertView == null) {
+ convertView = getLayoutInflater().inflate(
+ R.layout.parameter_field, container, false);
+ }
+
+ Class aClass = mParameterTypes[position];
+
+ ((TextView) convertView.findViewById(R.id.field_name)).setText(
+ TelephonyManagerTestApp.getShortTypeName(aClass.toString()) + ": ");
+ mEditTexts.add(convertView.findViewById(R.id.field_value));
+
+ return convertView;
+ }
+
+ @Override
+ public Object getItem(int position) {
+ if (mEditTexts == null || mEditTexts.size() <= position) {
+ return null;
+ }
+
+ return mEditTexts.get(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+ }
+}
diff --git a/testapps/TelephonyManagerTestApp/src/com/android/phone/testapps/telephonymanagertestapp/TelephonyManagerTestApp.java b/testapps/TelephonyManagerTestApp/src/com/android/phone/testapps/telephonymanagertestapp/TelephonyManagerTestApp.java
new file mode 100644
index 0000000..45c76a7
--- /dev/null
+++ b/testapps/TelephonyManagerTestApp/src/com/android/phone/testapps/telephonymanagertestapp/TelephonyManagerTestApp.java
@@ -0,0 +1,198 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.phone.testapps.telephonymanagertestapp;
+
+import android.app.ListActivity;
+import android.app.SearchManager;
+import android.content.Intent;
+import android.os.Bundle;
+import android.telephony.TelephonyManager;
+import android.view.Menu;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.ListView;
+import android.widget.SearchView;
+import android.widget.TextView;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Parameter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Main activity.
+ * Activity to choose which method to call.
+ */
+public class TelephonyManagerTestApp extends ListActivity implements
+ SearchView.OnQueryTextListener {
+ public static String TAG = "TMTestApp";
+
+ private List<Method> mMethods = new ArrayList<>();
+ private List<Method> mFilteredMethods = new ArrayList<>();
+ static Method sCurrentMethod;
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Initialize search view
+ getMenuInflater().inflate(R.menu.search_input, menu);
+ SearchView searchView = (SearchView) menu.findItem(R.id.search_input).getActionView();
+ SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
+ searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
+ searchView.setOnQueryTextListener(this);
+ searchView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
+ @Override
+ public void onViewDetachedFromWindow(View arg0) {
+ mFilteredMethods.clear();
+ mFilteredMethods.addAll(mMethods);
+ ((ListViewAdapter) mAdapter).notifyDataSetChanged();
+ }
+
+ @Override
+ public void onViewAttachedToWindow(View arg0) {
+ }
+ });
+ return true;
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ try {
+ Class c = TelephonyManager.class;
+ mMethods = Arrays.asList(c.getDeclaredMethods());
+ mFilteredMethods.addAll(mMethods);
+ mAdapter = new ListViewAdapter();
+ setListAdapter(mAdapter);
+ } catch (Throwable e) {
+ System.err.println(e);
+ finish();
+ }
+ }
+
+ private class ListViewAdapter extends BaseAdapter {
+ @Override
+ public int getCount() {
+ return mFilteredMethods.size();
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup container) {
+ if (mFilteredMethods.size() <= position) {
+ return null;
+ }
+
+ if (convertView == null) {
+ convertView = getLayoutInflater().inflate(
+ R.layout.abstract_method_view, container, false);
+ }
+
+ Method method = mFilteredMethods.get(position);
+ String tags = Modifier.toString(method.getModifiers()) + ' '
+ + getShortTypeName(method.getReturnType().toString());
+ String parameters = getParameters(method.getParameterTypes(), method.getParameters());
+ String methodName = (parameters == null) ? (method.getName() + "()") : method.getName();
+
+ ((TextView) convertView.findViewById(R.id.tags)).setText(tags);
+ ((TextView) convertView.findViewById(R.id.method_name)).setText(methodName);
+ ((TextView) convertView.findViewById(R.id.parameters)).setText(parameters);
+ return convertView;
+ }
+
+ @Override
+ public Object getItem(int position) {
+ if (mFilteredMethods.size() <= position) {
+ return null;
+ }
+
+ return mFilteredMethods.get(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+ }
+
+ @Override
+ public void onListItemClick(ListView l, View v, int position, long id) {
+ sCurrentMethod = mFilteredMethods.get(position);
+ Intent intent = new Intent(this, CallingMethodActivity.class);
+
+ startActivity(intent);
+ }
+
+ @Override
+ public boolean onQueryTextSubmit(String query) {
+ filterMethods(query);
+ return true;
+ }
+
+ @Override
+ public boolean onQueryTextChange(String newText) {
+ return false;
+ }
+
+ private void filterMethods(String text) {
+ mFilteredMethods.clear();
+
+ if (text == null || text.isEmpty()) {
+ mFilteredMethods.addAll(mMethods);
+ } else {
+ for (Method method : mMethods) {
+ if (method.getName().contains(text)) {
+ mFilteredMethods.add(method);
+ }
+ }
+ }
+
+ ((ListViewAdapter) mAdapter).notifyDataSetChanged();
+
+ }
+
+ private String getParameters(Class<?>[] types, Parameter[] parameters) {
+ if (types == null || types.length == 0) {
+ return null;
+ }
+
+ StringBuilder sb = new StringBuilder();
+ sb.append('(');
+ for (int j = 0; j < types.length; j++) {
+ String typeName = getShortTypeName(types[j].getTypeName());
+ sb.append(typeName);
+ if (j < (types.length - 1)) {
+ sb.append(", ");
+ }
+ }
+ sb.append(')');
+
+ return sb.toString();
+ }
+
+ static String getShortTypeName(String typeName) {
+ if (typeName == null) {
+ return null;
+ }
+
+ String[] parts = typeName.split("[. ]");
+ return parts[parts.length - 1];
+ }
+}