Merge "A simple app uses aconfig flag"
This commit is contained in:
@@ -1,3 +1,45 @@
|
||||
package {
|
||||
default_applicable_licenses: ["Android-Apache-2.0"],
|
||||
}
|
||||
|
||||
android_app {
|
||||
name: "AconfigDemoActivity",
|
||||
manifest: "AndroidManifest.xml",
|
||||
srcs: ["src/com/example/android/aconfig/demo/activity/AconfigDemoActivity.java"],
|
||||
certificate: "platform",
|
||||
sdk_version: "current",
|
||||
static_libs: [
|
||||
"ContentProvider",
|
||||
],
|
||||
optimize: {
|
||||
enabled: true,
|
||||
proguard_compatibility: false,
|
||||
shrink: true,
|
||||
optimize: false,
|
||||
obfuscate: false,
|
||||
shrink_resources: true,
|
||||
},
|
||||
}
|
||||
|
||||
aconfig_declarations {
|
||||
name: "aconfig_demo_flags",
|
||||
package: "com.example.android.aconfig.demo.activity",
|
||||
srcs: ["aconfig_demo_flags.aconfig"],
|
||||
}
|
||||
|
||||
|
||||
java_aconfig_library {
|
||||
name: "aconfig_demo_flags_lib",
|
||||
aconfig_declarations: "aconfig_demo_flags",
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "ContentProvider",
|
||||
srcs: [
|
||||
"src/com/example/android/aconfig/demo/activity/ContentProvider.java",
|
||||
],
|
||||
sdk_version: "current",
|
||||
static_libs: [
|
||||
"aconfig_demo_flags_lib",
|
||||
],
|
||||
}
|
||||
|
||||
34
samples/AconfigDemo/AndroidManifest.xml
Normal file
34
samples/AconfigDemo/AndroidManifest.xml
Normal file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2007 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.
|
||||
-->
|
||||
|
||||
<!-- Declare the contents of this Android application. The namespace
|
||||
attribute brings in the Android platform namespace, and the package
|
||||
supplies a unique name for the application. When writing your
|
||||
own application, the package name must be changed from "com.example.*"
|
||||
to come from a domain that you own or have control over. -->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.android.aconfig.demo.activity">
|
||||
<uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
|
||||
<application android:label="Hello!">
|
||||
<activity android:name="AconfigDemoActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
7
samples/AconfigDemo/aconfig_demo_flags.aconfig
Normal file
7
samples/AconfigDemo/aconfig_demo_flags.aconfig
Normal file
@@ -0,0 +1,7 @@
|
||||
package: "com.example.android.aconfig.demo.activity"
|
||||
|
||||
flag {
|
||||
name: "append_content"
|
||||
namespace: "aconfig_demo_ns"
|
||||
description: "This flag is buildtime flag"
|
||||
}
|
||||
32
samples/AconfigDemo/res/layout/main.xml
Normal file
32
samples/AconfigDemo/res/layout/main.xml
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2007 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:padding="4dip"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<TextView
|
||||
android:id="@+id/simpleTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="#444444"
|
||||
android:textSize="25sp"
|
||||
android:autoText="true"
|
||||
android:capitalize="sentences"
|
||||
android:textStyle="bold|italic"/>
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2007 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.example.android.aconfig.demo.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.view.WindowManager;
|
||||
|
||||
|
||||
/**
|
||||
* A minimal "Hello, World!" application.
|
||||
*/
|
||||
public class AconfigDemoActivity extends Activity {
|
||||
/**
|
||||
* Called with the activity is first created.
|
||||
*/
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.main);
|
||||
TextView simpleTextView = (TextView) findViewById(R.id.simpleTextView);
|
||||
simpleTextView.setText("Show Flags: \n\n");
|
||||
|
||||
ContentProvider cp = new ContentProvider();
|
||||
simpleTextView.append(cp.getContent());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2007 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.example.android.aconfig.demo.activity;
|
||||
|
||||
/**
|
||||
* A minimal "Hello, World!" application.
|
||||
*/
|
||||
public class ContentProvider {
|
||||
|
||||
public ContentProvider() {};
|
||||
|
||||
public String getContent() {
|
||||
|
||||
StringBuilder sBuffer = new StringBuilder();
|
||||
|
||||
if (Flags.appendContent()) {
|
||||
sBuffer.append("The flag is ON!!\n");
|
||||
} else {
|
||||
sBuffer.append("The flag is OFF!!\n");
|
||||
}
|
||||
|
||||
return sBuffer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
15
samples/AconfigDemo/tests/Android.bp
Normal file
15
samples/AconfigDemo/tests/Android.bp
Normal file
@@ -0,0 +1,15 @@
|
||||
package {
|
||||
default_applicable_licenses: ["Android-Apache-2.0"],
|
||||
}
|
||||
|
||||
android_test {
|
||||
name: "AconfigDemo_ContentProvide_Test",
|
||||
srcs: ["src/com/example/android/aconfig/demo/activity/ContentProviderTests.java"],
|
||||
certificate: "platform",
|
||||
static_libs: [
|
||||
"ContentProvider",
|
||||
"junit",
|
||||
"androidx.test.runner",
|
||||
],
|
||||
manifest: "AndroidManifest.xml",
|
||||
}
|
||||
32
samples/AconfigDemo/tests/AndroidManifest.xml
Normal file
32
samples/AconfigDemo/tests/AndroidManifest.xml
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2008 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.example.android.aconfig.demo.activity.tests">
|
||||
<uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
|
||||
|
||||
<!-- We add an application tag here just so that we can indicate that
|
||||
this package needs to link against the android.test library,
|
||||
which is needed when building test cases. -->
|
||||
<application>
|
||||
<uses-library android:name="android.test.runner" />
|
||||
</application>
|
||||
|
||||
<instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
|
||||
android:targetPackage="com.example.android.aconfig.demo.activity.tests"
|
||||
android:label="AconfigDemoActivity sample tests">
|
||||
</instrumentation>
|
||||
</manifest>
|
||||
1
samples/AconfigDemo/tests/build.properties
Normal file
1
samples/AconfigDemo/tests/build.properties
Normal file
@@ -0,0 +1 @@
|
||||
tested.project.dir=..
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.example.android.aconfig.demo.activity;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public final class ContentProviderTests {
|
||||
|
||||
@Test
|
||||
public void testFlag() {
|
||||
assertFalse(Flags.appendContent());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user