cmsdk: Update binder transaction tests for new interfaces.

Change-Id: I79352dc36a4934f9821c5b487df0fb19a7ebc693
This commit is contained in:
Adnan Begovic 2016-02-22 14:12:05 -08:00
parent 6c1aa2f115
commit 9c902f898e
3 changed files with 290 additions and 80 deletions

View File

@ -21,8 +21,11 @@ import android.os.Binder;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.Log;
import android.util.Pair;
import org.cyanogenmod.tests.CyanogenModTestApplication;
import org.cyanogenmod.tests.versioning.unit.apiv2.ApiV2PriorReleaseInterfaces;
import org.cyanogenmod.tests.versioning.unit.apiv4.ApiV4PriorReleaseInterfaces;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -38,6 +41,8 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* These tests validate the enumerated binder transaction call ids per each
@ -57,6 +62,7 @@ import java.util.Map;
@RunWith(Parameterized.class)
@LargeTest
public class BinderTransactionTest extends AndroidTestCase {
private static final String TAG = BinderTransactionTest.class.getSimpleName();
private static final String STUB_SUFFIX = "$Stub";
private static final String CYANOGENMOD_NAMESPACE = "cyanogenmod";
private static final String TRANSACTION_PREFIX = "TRANSACTION_";
@ -69,7 +75,8 @@ public class BinderTransactionTest extends AndroidTestCase {
private static Context sContext;
private static ArrayList<String> mKnownSdkClasses;
private static Map<String, Integer> mApiMethodsAndValues = new HashMap<String, Integer>();
private static Map<String, Map<String, Integer>> mApiMethodsAndValues =
new HashMap<String, Map<String, Integer>>();
@Before
public void setUp() throws Exception {
@ -89,14 +96,28 @@ public class BinderTransactionTest extends AndroidTestCase {
mKnownSdkClasses = MagicalDexHelper.getLoadedClasses(
CyanogenModTestApplication.getStaticApplicationContext(), CYANOGENMOD_NAMESPACE);
sContext = CyanogenModTestApplication.getStaticApplicationContext();
mApiMethodsAndValues.putAll(ApiV2PriorReleaseInterfaces.getInterfaces());
addInterfaces(ApiV2PriorReleaseInterfaces.getInterfaces());
addInterfaces(ApiV4PriorReleaseInterfaces.getInterfaces());
}
private static void addInterfaces(Map<String, Map<String, Integer>> mapToAdd) {
for (String key : mapToAdd.keySet()) {
if (mApiMethodsAndValues.get(key) != null) {
Map<String, Integer> internalMap = mApiMethodsAndValues.get(key);
internalMap.putAll(mapToAdd.get(key));
} else {
Map<String, Integer> internalMap = mapToAdd.get(key);
mApiMethodsAndValues.put(key, internalMap);
}
}
}
@Parameterized.Parameters
public static Collection<Object[]> data() {
doSetup();
//Ughhh, lets pretend this never happened
ArrayList<String> targetFields = new ArrayList<String>();
ArrayList<Pair<String, String>> targetClassAndFields =
new ArrayList<Pair<String, String>>();
ArrayList<Integer> actualValues = new ArrayList<Integer>();
for (String sClazz : mKnownSdkClasses) {
@ -105,12 +126,24 @@ public class BinderTransactionTest extends AndroidTestCase {
Class clazz = MagicalDexHelper.loadClassForNameSpace(CyanogenModTestApplication
.getStaticApplicationContext(), sClazz);
Field[] fields = clazz.getDeclaredFields();
Pattern pattern = Pattern.compile("\\.([\\w]+)\\$");
Matcher matcher = pattern.matcher(clazz.getName());
String className = null;
if (matcher.find()) {
className = matcher.group(1).substring(0, matcher.group(1).length());
}
for (Field field : fields) {
if (field.getName().startsWith(TRANSACTION_PREFIX)) {
field.setAccessible(true);
targetFields.add(field.getName()
.substring(TRANSACTION_PREFIX.length()));
String fieldName = field.getName().substring(
TRANSACTION_PREFIX.length());
fieldName = fieldName.split("_")[0];
Pair<String, String> classAndField = new Pair<String, String>(
className, fieldName);
Log.d(TAG, "Adding: " + classAndField.first + " with field "
+ classAndField.second);
targetClassAndFields.add(classAndField);
try {
actualValues.add(field.getInt(clazz));
} catch (IllegalAccessException e) {
@ -123,23 +156,28 @@ public class BinderTransactionTest extends AndroidTestCase {
}
}
}
Object[][] values = new Object[targetFields.size()][3];
Object[][] values = new Object[targetClassAndFields.size()][3];
for (int i = 0; i < targetFields.size(); i++) {
String targetField = targetFields.get(i);
values[i][0] = targetField;
values[i][1] = lookupValueForField(targetField);
for (int i = 0; i < targetClassAndFields.size(); i++) {
Pair<String, String> targetClassAndField = targetClassAndFields.get(i);
values[i][0] = targetClassAndField.second;
values[i][1] = lookupValueForField(targetClassAndField.first,
targetClassAndField.second);
values[i][2] = actualValues.get(i);
}
return Arrays.asList(values);
}
//Look up the target fields value from a prior release
private static Object lookupValueForField(String fieldName) {
if (!mApiMethodsAndValues.containsKey(fieldName)) {
private static Object lookupValueForField(String clazz, String fieldName) {
Log.d(TAG, "Looking up: " + clazz + " with field "
+ fieldName);
Map<String, Integer> internalMap = mApiMethodsAndValues.get(clazz);
if (internalMap == null || !internalMap.containsKey(fieldName)) {
Log.d(TAG, "Internal map for " + clazz + " is null or doesn't contain entry");
return NOT_FROM_PRIOR_RELEASE;
}
return mApiMethodsAndValues.get(fieldName);
return internalMap.get(fieldName);
}
public BinderTransactionTest(String targetField, Integer expectedValue, Integer actualValue) {
@ -150,7 +188,8 @@ public class BinderTransactionTest extends AndroidTestCase {
@Test
public void testBinderTransactionValidation() {
System.out.print("Testing: " + mField);
Log.d(TAG, "Testing: " + mField + " with expected value of " + mExpectedValue
+ " and actual value of " + mActualValue);
if (mExpectedValue == NOT_FROM_PRIOR_RELEASE) {
//This is a new interface, no need to test against
return;

View File

@ -15,6 +15,7 @@
*/
package org.cyanogenmod.tests.versioning.unit.apiv2;
import java.util.HashMap;
import java.util.Map;
@ -22,97 +23,121 @@ import java.util.Map;
* Created by adnan on 2/4/16.
*/
public class ApiV2PriorReleaseInterfaces {
private static Map<String, Integer> mApiMethodsAndValues = new HashMap<String, Integer>();
private static Map<String, Map<String, Integer>> mApiMethodsAndValues =
new HashMap<String, Map<String, Integer>>();
//Profiles Aidl (IProfileManager)
static {
Map<String, Integer> profilesMap = getInternalInterfaceMap("IProfileManager");
// APRICOT + BOYSENBERRY + CANTALOUPE
mApiMethodsAndValues.put("setActiveProfile", 1);
mApiMethodsAndValues.put("etActiveProfileByName", 2);
mApiMethodsAndValues.put("getActiveProfile", 3);
mApiMethodsAndValues.put("addProfile", 4);
mApiMethodsAndValues.put("removeProfile", 5);
mApiMethodsAndValues.put("updateProfile", 6);
mApiMethodsAndValues.put("getProfile", 7);
mApiMethodsAndValues.put("getProfileByName", 8);
mApiMethodsAndValues.put("getProfiles", 9);
mApiMethodsAndValues.put("profileExists", 10);
mApiMethodsAndValues.put("profileExistsByName", 11);
mApiMethodsAndValues.put("notificationGroupExistsByName", 12);
mApiMethodsAndValues.put("getNotificationGroups", 13);
mApiMethodsAndValues.put("addNotificationGroup", 14);
mApiMethodsAndValues.put("removeNotificationGroup", 15);
mApiMethodsAndValues.put("updateNotificationGroup", 16);
mApiMethodsAndValues.put("getNotificationGroupForPackage", 17);
mApiMethodsAndValues.put("getNotificationGroup", 18);
mApiMethodsAndValues.put("resetAll", 19);
//FUTURE RELEASE
profilesMap.put("setActiveProfile", 1);
profilesMap.put("etActiveProfileByName", 2);
profilesMap.put("getActiveProfile", 3);
profilesMap.put("addProfile", 4);
profilesMap.put("removeProfile", 5);
profilesMap.put("updateProfile", 6);
profilesMap.put("getProfile", 7);
profilesMap.put("getProfileByName", 8);
profilesMap.put("getProfiles", 9);
profilesMap.put("profileExists", 10);
profilesMap.put("profileExistsByName", 11);
profilesMap.put("notificationGroupExistsByName", 12);
profilesMap.put("getNotificationGroups", 13);
profilesMap.put("addNotificationGroup", 14);
profilesMap.put("removeNotificationGroup", 15);
profilesMap.put("updateNotificationGroup", 16);
profilesMap.put("getNotificationGroupForPackage", 17);
profilesMap.put("getNotificationGroup", 18);
profilesMap.put("resetAll", 19);
}
//PartnerInterface Aidl (IPartnerInterface)
static {
Map<String, Integer> partnerMap = getInternalInterfaceMap("IPartnerInterface");
// APRICOT + BOYSENBERRY + CANTALOUPE
mApiMethodsAndValues.put("setAirplaneModeEnabled_0", 1);
mApiMethodsAndValues.put("setMobileDataEnabled_1", 2);
mApiMethodsAndValues.put("setZenMode", 3);
mApiMethodsAndValues.put("shutdown", 4);
mApiMethodsAndValues.put("reboot", 5);
mApiMethodsAndValues.put("getCurrentHotwordPackageName", 6);
//FUTURE RELEASE
partnerMap.put("setAirplaneModeEnabled", 1);
partnerMap.put("setMobileDataEnabled", 2);
partnerMap.put("setZenMode", 3);
partnerMap.put("shutdown", 4);
partnerMap.put("reboot", 5);
partnerMap.put("getCurrentHotwordPackageName", 6);
}
//CMHardwareManager Aidl (ICMHardwareService)
static {
Map<String, Integer> hardwareMap = getInternalInterfaceMap("ICMHardwareService");
// APRICOT + BOYSENBERRY + CANTALOUPE
mApiMethodsAndValues.put("getSupportedFeatures_0", 1);
mApiMethodsAndValues.put("get_1", 2);
mApiMethodsAndValues.put("set", 3);
mApiMethodsAndValues.put("getDisplayColorCalibration", 4);
mApiMethodsAndValues.put("setDisplayColorCalibration", 5);
mApiMethodsAndValues.put("getNumGammaControls", 6);
mApiMethodsAndValues.put("getDisplayGammaCalibration", 7);
mApiMethodsAndValues.put("setDisplayGammaCalibration", 8);
mApiMethodsAndValues.put("getVibratorIntensity", 9);
mApiMethodsAndValues.put("setVibratorIntensity", 10);
mApiMethodsAndValues.put("getLtoSource", 11);
mApiMethodsAndValues.put("getLtoDestination", 12);
mApiMethodsAndValues.put("getLtoDownloadInterval", 13);
mApiMethodsAndValues.put("getSerialNumber", 14);
mApiMethodsAndValues.put("requireAdaptiveBacklightForSunlightEnhancement", 15);
mApiMethodsAndValues.put("getDisplayModes", 16);
mApiMethodsAndValues.put("getCurrentDisplayMode", 17);
mApiMethodsAndValues.put("getDefaultDisplayMode", 18);
mApiMethodsAndValues.put("setDisplayMode", 19);
mApiMethodsAndValues.put("writePersistentBytes", 20);
mApiMethodsAndValues.put("readPersistentBytes", 21);
mApiMethodsAndValues.put("getThermalState", 22);
mApiMethodsAndValues.put("registerThermalListener", 23);
mApiMethodsAndValues.put("unRegisterThermalListener", 24);
//FUTURE RELEASE
hardwareMap.put("getSupportedFeatures", 1);
hardwareMap.put("get", 2);
hardwareMap.put("set", 3);
hardwareMap.put("getDisplayColorCalibration", 4);
hardwareMap.put("setDisplayColorCalibration", 5);
hardwareMap.put("getNumGammaControls", 6);
hardwareMap.put("getDisplayGammaCalibration", 7);
hardwareMap.put("setDisplayGammaCalibration", 8);
hardwareMap.put("getVibratorIntensity", 9);
hardwareMap.put("setVibratorIntensity", 10);
hardwareMap.put("getLtoSource", 11);
hardwareMap.put("getLtoDestination", 12);
hardwareMap.put("getLtoDownloadInterval", 13);
hardwareMap.put("getSerialNumber", 14);
hardwareMap.put("requireAdaptiveBacklightForSunlightEnhancement", 15);
hardwareMap.put("getDisplayModes", 16);
hardwareMap.put("getCurrentDisplayMode", 17);
hardwareMap.put("getDefaultDisplayMode", 18);
hardwareMap.put("setDisplayMode", 19);
hardwareMap.put("writePersistentBytes", 20);
hardwareMap.put("readPersistentBytes", 21);
hardwareMap.put("getThermalState", 22);
hardwareMap.put("registerThermalListener", 23);
hardwareMap.put("unRegisterThermalListener", 24);
}
//CMStatusBarManager Aidl (ICMStatusBarManager)
static {
Map<String, Integer> statusBarMap = getInternalInterfaceMap("ICMStatusBarManager");
// APRICOT + BOYSENBERRY + CANTALOUPE
mApiMethodsAndValues.put("createCustomTileWithTag", 1);
mApiMethodsAndValues.put("removeCustomTileWithTag", 2);
mApiMethodsAndValues.put("registerListener", 3);
mApiMethodsAndValues.put("unregisterListener", 4);
mApiMethodsAndValues.put("removeCustomTileFromListener", 5);
//FUTURE RELEASE
statusBarMap.put("createCustomTileWithTag", 1);
statusBarMap.put("removeCustomTileWithTag", 2);
statusBarMap.put("registerListener", 3);
statusBarMap.put("unregisterListener", 4);
statusBarMap.put("removeCustomTileFromListener", 5);
}
//AppSuggestManager Aidl (IAppSuggestManager)
static {
mApiMethodsAndValues.put("handles_0", 1);
mApiMethodsAndValues.put("getSuggestions_1", 2);
Map<String, Integer> suggestMap = getInternalInterfaceMap("IAppSuggestManager");
// APRICOT + BOYSENBERRY + CANTALOUPE
suggestMap.put("handles", 1);
suggestMap.put("getSuggestions", 2);
}
public static Map<String, Integer> getInterfaces() {
//CMTelephonyManager Aidl (ICMTelephonyManager)
static {
Map<String, Integer> telephonyMap = getInternalInterfaceMap("ICMTelephonyManager");
// APRICOT + BOYSENBERRY + CANTALOUPE
telephonyMap.put("getSubInformation", 1);
telephonyMap.put("isSubActive", 2);
telephonyMap.put("isDataConnectionSelectedOnSub", 3);
telephonyMap.put("isDataConnectionEnabled", 4);
telephonyMap.put("setSubState", 5);
telephonyMap.put("setDataConnectionSelectedOnSub", 6);
telephonyMap.put("setDataConnectionState", 7);
telephonyMap.put("setDefaultPhoneSub", 8);
telephonyMap.put("setDefaultSmsSub", 9);
}
protected static Map<String, Integer> getInternalInterfaceMap(String targetInterface) {
Map<String, Integer> internalMap = mApiMethodsAndValues.get(targetInterface);
if (internalMap == null) {
internalMap = new HashMap<String, Integer>();
mApiMethodsAndValues.put(targetInterface, internalMap);
return internalMap;
}
return internalMap;
}
public static Map<String, Map<String, Integer>> getInterfaces() {
return mApiMethodsAndValues;
}
}

View File

@ -0,0 +1,146 @@
/**
* Copyright (c) 2016, The CyanogenMod 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 org.cyanogenmod.tests.versioning.unit.apiv4;
import java.util.HashMap;
import java.util.Map;
/**
* Created by adnan on 2/19/16.
*/
public class ApiV4PriorReleaseInterfaces {
private static Map<String, Map<String, Integer>> mApiMethodsAndValues =
new HashMap<String, Map<String, Integer>>();
//Profiles Aidl (IProfileManager)
static {
Map<String, Integer> profilesMap = getInternalInterfaceMap("IProfileManager");
// APRICOT + BOYSENBERRY + CANTALOUPE to 19
// DRAGONFRUIT BEGIN
profilesMap.put("isEnabled", 20);
}
//PartnerInterface Aidl (IPartnerInterface)
static {
Map<String, Integer> partnerMap = getInternalInterfaceMap("IPartnerInterface");
// APRICOT + BOYSENBERRY + CANTALOUPE to 6
// DRAGONFRUIT BEGIN
partnerMap.put("setZenModeWithDuration", 7);
}
//CMHardwareManager Aidl (ICMHardwareService)
static {
Map<String, Integer> hardwareMap = getInternalInterfaceMap("ICMHardwareService");
// APRICOT + BOYSENBERRY + CANTALOUPE to 24
// DRAGONFRUIT BEGIN
hardwareMap.put("isSunlightEnhancementSelfManaged", 25);
hardwareMap.put("getUniqueDeviceId", 26);
}
//CMStatusBarManager Aidl (ICMStatusBarManager)
static {
// APRICOT + BOYSENBERRY + CANTALOUPE to 5
// DRAGONFRUIT BEGIN
}
//AppSuggestManager Aidl (IAppSuggestManager)
static {
// APRICOT + BOYSENBERRY + CANTALOUPE to 2
// DRAGONFRUIT BEGIN
}
//CMTelephonyManager Aidl (ICMTelephonyManager)
static {
// APRICOT + BOYSENBERRY + CANTALOUPE to 9
// DRAGONFRUIT BEGIN
}
//PerformanceManager Aidl (IPerformanceManager)
static {
Map<String, Integer> perfMap = getInternalInterfaceMap("IPerformanceManager");
// DRAGONFRUIT BEGIN
perfMap.put("cpuBoost", 1);
perfMap.put("setPowerProfile", 2);
perfMap.put("getPowerProfile", 3);
perfMap.put("getNumberOfProfiles", 4);
perfMap.put("getProfileHasAppProfiles", 5);
}
//ExternalViewProviderFactory Aidl (IExternalViewProviderFactory)
static {
Map<String, Integer> extProviderMap =
getInternalInterfaceMap("IExternalViewProviderFactory");
// DRAGONFRUIT BEGIN
extProviderMap.put("createExternalView", 1);
}
//ExternalViewProvider Aidl (IExternalViewProvider)
static {
Map<String, Integer> extViewProviderMap =
getInternalInterfaceMap("IExternalViewProvider");
// DRAGONFRUIT BEGIN
extViewProviderMap.put("onAttach", 1);
extViewProviderMap.put("onStart", 2);
extViewProviderMap.put("onResume", 3);
extViewProviderMap.put("onPause", 4);
extViewProviderMap.put("onStop", 5);
extViewProviderMap.put("onDetach", 6);
extViewProviderMap.put("alterWindow", 7);
}
//KeyguardExternalViewCallbacks Aidl (IKeyguardExternalViewCallbacks)
static {
Map<String, Integer> kgExtViewCbMap =
getInternalInterfaceMap("IKeyguardExternalViewCallbacks");
// DRAGONFRUIT BEGIN
kgExtViewCbMap.put("requestDismiss", 1);
kgExtViewCbMap.put("requestDismissAndStartActivity", 2);
kgExtViewCbMap.put("collapseNotificationPanel", 3);
kgExtViewCbMap.put("setInteractivity", 4);
}
//KeyguardExternalViewProvider Aidl (IKeyguardExternalViewProvider)
static {
Map<String, Integer> kgExtViewProviderMap =
getInternalInterfaceMap("IKeyguardExternalViewProvider");
// DRAGONFRUIT BEGIN
kgExtViewProviderMap.put("onAttach", 1);
kgExtViewProviderMap.put("onDetach", 2);
kgExtViewProviderMap.put("onKeyguardShowing", 3);
kgExtViewProviderMap.put("onKeyguardDismissed" , 4);
kgExtViewProviderMap.put("onBouncerShowing", 5);
kgExtViewProviderMap.put("onScreenTurnedOn", 6);
kgExtViewProviderMap.put("onScreenTurnedOff", 7);
kgExtViewProviderMap.put("registerCallback", 8);
kgExtViewProviderMap.put("unregisterCallback", 9);
kgExtViewProviderMap.put("alterWindow", 10);
}
protected static Map<String, Integer> getInternalInterfaceMap(String targetInterface) {
Map<String, Integer> internalMap = mApiMethodsAndValues.get(targetInterface);
if (internalMap == null) {
internalMap = new HashMap<String, Integer>();
mApiMethodsAndValues.put(targetInterface, internalMap);
return internalMap;
}
return internalMap;
}
public static Map<String, Map<String, Integer>> getInterfaces() {
return mApiMethodsAndValues;
}
}