Merge "APK Cache Demo App" am: cd3a0fe97c
am: 09408cb0e6
Change-Id: I04a47027504c8e6c7c292ee940ba11fe082fac20
This commit is contained in:
30
samples/apkcachetest/Android.mk
Normal file
30
samples/apkcachetest/Android.mk
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2016 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_PACKAGE_NAME := ApkCacheTest
|
||||||
|
|
||||||
|
LOCAL_CERTIFICATE := shared
|
||||||
|
|
||||||
|
LOCAL_PROGUARD_ENABLED := disabled
|
||||||
|
|
||||||
|
include $(BUILD_PACKAGE)
|
||||||
31
samples/apkcachetest/AndroidManifest.xml
Normal file
31
samples/apkcachetest/AndroidManifest.xml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?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="com.android.apkcachetest" >
|
||||||
|
|
||||||
|
<application android:label="ApkCacheTest">
|
||||||
|
<activity android:name=".Main" android:label="ApkCacheTest">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
</manifest>
|
||||||
20
samples/apkcachetest/res/layout/hello_activity.xml
Normal file
20
samples/apkcachetest/res/layout/hello_activity.xml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?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
|
||||||
|
-->
|
||||||
|
|
||||||
|
<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/text"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
69
samples/apkcachetest/src/com/android/apkcachetest/Main.java
Normal file
69
samples/apkcachetest/src/com/android/apkcachetest/Main.java
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* 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 com.android.apkcachetest;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.FileUtils;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class Main extends Activity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
setContentView(R.layout.hello_activity);
|
||||||
|
File preloadsFileCache = getPreloadsFileCache();
|
||||||
|
TextView txt = (TextView) findViewById(R.id.text);
|
||||||
|
if (!getApplicationInfo().isPrivilegedApp()) {
|
||||||
|
txt.append("WARNING: App must be installed in /system/priv-app directory to access "
|
||||||
|
+ "preloads cache\n");
|
||||||
|
}
|
||||||
|
txt.append("PreloadsFileCache app directory: " + preloadsFileCache + '\n');
|
||||||
|
if (!preloadsFileCache.exists()) {
|
||||||
|
txt.append(" --- Directory does not exist ---\n");
|
||||||
|
} else {
|
||||||
|
File[] files = preloadsFileCache.listFiles();
|
||||||
|
if (files == null || files.length == 0) {
|
||||||
|
txt.append(" --- No files found ---\n");
|
||||||
|
} else {
|
||||||
|
for (File file : files) {
|
||||||
|
try {
|
||||||
|
txt.append(" " + file.getName() + ": [" + readTextFile(file) + "]\n");
|
||||||
|
} catch (IOException e) {
|
||||||
|
txt.append(" " + file.getName() + ": Error " + e + "\n");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
txt.append(files.length + " files");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String readTextFile(File file) throws IOException {
|
||||||
|
String s = FileUtils.readTextFile(file, 100, "...");
|
||||||
|
if (s != null) {
|
||||||
|
s = s.replaceAll("[^\\x20-\\x7E]+", " ");
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user