upload android base code part8

This commit is contained in:
August 2018-08-08 20:10:12 +08:00
parent 841ae54672
commit 5425409085
57075 changed files with 9846578 additions and 0 deletions

View file

@ -0,0 +1,33 @@
#
# 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.
#
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := tests
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
LOCAL_PACKAGE_NAME := CtsInstantCookieApp2
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_DEX_PREOPT := false
include $(BUILD_PACKAGE)

View file

@ -0,0 +1,30 @@
<?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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test.instant.cookie.mokie"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application/>
<instrumentation
android:name="android.support.test.runner.AndroidJUnitRunner"
android:targetPackage="test.instant.cookie.mokie" />
</manifest>

View file

@ -0,0 +1,112 @@
/*
* 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.
*/
package test.instant.cookie;
import android.content.pm.PackageManager;
import android.os.Debug;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@RunWith(AndroidJUnit4.class)
public class CookieTest {
@Test
public void testCookieUpdateAndRetrieval() throws Exception {
Debug.waitForDebugger();
PackageManager pm = InstrumentationRegistry.getContext().getPackageManager();
// We should be an instant app
assertTrue(pm.isInstantApp());
// The max cookie size is greater than zero
assertTrue(pm.getInstantAppCookieMaxSize() > 0);
// Initially there is no cookie
byte[] cookie = pm.getInstantAppCookie();
assertTrue(cookie != null && cookie.length == 0);
// Setting a cookie below max size should work
assertTrue(pm.setInstantAppCookie("1".getBytes()));
// // Setting a cookie above max size should not work
// assertFalse(pm.setInstantAppCookie(
// new byte[pm.getInstantAppCookieMaxSize() + 1]));
//
// // Ensure cookie not modified
// assertEquals("1", new String(pm.getInstantAppCookie()));
}
// @Test
// public void testCookiePersistedAcrossInstantInstalls1() throws Exception {
// PackageManager pm = InstrumentationRegistry.getContext().getPackageManager();
//
// // Set a cookie to later check when reinstalled as instant app
// assertTrue(pm.setInstantAppCookie("2".getBytes()));
// }
//
// @Test
// public void testCookiePersistedAcrossInstantInstalls2() throws Exception {
// PackageManager pm = InstrumentationRegistry.getContext().getPackageManager();
//
// // After the upgrade the cookie should be the same
// assertEquals("2", new String(pm.getInstantAppCookie()));
// }
//
// @Test
// public void testCookiePersistedUpgradeFromInstant1() throws Exception {
// PackageManager pm = InstrumentationRegistry.getContext().getPackageManager();
//
// // Make sure we are an instant app
// assertTrue(pm.isInstantApp());
//
// // Set a cookie to later check when upgrade to a normal app
// assertTrue(pm.setInstantAppCookie("3".getBytes()));
// }
//
// @Test
// public void testCookiePersistedUpgradeFromInstant2() throws Exception {
// PackageManager pm = InstrumentationRegistry.getContext().getPackageManager();
//
// // Make sure we are not an instant app
// assertFalse(pm.isInstantApp());
//
// // The cookie survives the upgrade to a normal app
// assertEquals("3", new String(pm.getInstantAppCookie()));
// }
//
// @Test
// public void testCookieResetOnNonInstantReinstall1() throws Exception {
// PackageManager pm = InstrumentationRegistry.getContext().getPackageManager();
//
// // Set a cookie to later check when reinstalled as normal app
// assertTrue(pm.setInstantAppCookie("4".getBytes()));
// }
//
// @Test
// public void testCookieResetOnNonInstantReinstall2() throws Exception {
// PackageManager pm = InstrumentationRegistry.getContext().getPackageManager();
//
// // The cookie should have been wiped if non-instant app is uninstalled
// byte[] cookie = pm.getInstantAppCookie();
// assertTrue(cookie != null && cookie.length == 0);
// }
}