Add Link Capacity Estimation (LCE) demo app.

Change-Id: I42f6a4fa5c989559db75d6d658081b44f7850b7a
This commit is contained in:
fenglu
2016-03-10 13:54:16 -08:00
parent c3b3dc1774
commit a442d40246
8 changed files with 261 additions and 0 deletions

View File

@@ -380,6 +380,7 @@ development/samples/Home samples/${PLATFORM_NAME}/legacy/H
development/samples/HoneycombGallery samples/${PLATFORM_NAME}/legacy/HoneycombGallery development/samples/HoneycombGallery samples/${PLATFORM_NAME}/legacy/HoneycombGallery
development/samples/JetBoy samples/${PLATFORM_NAME}/legacy/JetBoy development/samples/JetBoy samples/${PLATFORM_NAME}/legacy/JetBoy
development/samples/KeyChainDemo samples/${PLATFORM_NAME}/legacy/KeyChainDemo development/samples/KeyChainDemo samples/${PLATFORM_NAME}/legacy/KeyChainDemo
development/samples/LceDemo samples/${PLATFORM_NAME}/legacy/LceDemo
development/samples/LunarLander samples/${PLATFORM_NAME}/legacy/LunarLander development/samples/LunarLander samples/${PLATFORM_NAME}/legacy/LunarLander
development/samples/MultiResolution samples/${PLATFORM_NAME}/legacy/MultiResolution development/samples/MultiResolution samples/${PLATFORM_NAME}/legacy/MultiResolution
development/samples/NotePad samples/${PLATFORM_NAME}/legacy/NotePad development/samples/NotePad samples/${PLATFORM_NAME}/legacy/NotePad

View File

@@ -0,0 +1,19 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := samples
# Only compile source java files in this apk.
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := LceDemo
LOCAL_SDK_VERSION := current
LOCAL_MODULE_TAGS := tests
include $(BUILD_PACKAGE)
# Use the following include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.lce">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-sdk
android:minSdkVersion="23" />
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true">
<activity
android:name=".LceDemoActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.android.lce.LceDemoActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Call LCE Service"
android:id="@+id/lceButton"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LCE Info Log\n"
android:id="@+id/lceText"
android:layout_marginTop="62dp"
android:layout_below="@+id/lceButton"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:maxLines="20"
android:scrollbars = "vertical"
android:layout_alignParentEnd="true" />
</RelativeLayout>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
</resources>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<resources>
<string name="app_name">LCE Demo App</string>
<string name="action_settings">Settings</string>
</resources>

View File

@@ -0,0 +1,87 @@
/*
* 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.
*/
package com.example.android.lce;
import android.annotation.TargetApi;
import android.app.Activity;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.TextView;
public class LceDemoActivity extends Activity {
private ConnectivityManager connectityManager;
@Override
@TargetApi(23)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Default toolbar action handler.
setContentView(R.layout.activity_lce_demo);
final TextView text = (TextView) findViewById(R.id.lceText);
text.setMovementMethod(new ScrollingMovementMethod());
// Get an instance of ConnectivityManager.
connectityManager = (ConnectivityManager)getSystemService(
getApplicationContext().CONNECTIVITY_SERVICE);
// Create a handler to update text on the screen.
final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
text.append((String)msg.obj);
super.handleMessage(msg);
}
};
// Now register the network call back function.
NetworkRequest.Builder builder = new NetworkRequest.Builder();
connectityManager.registerNetworkCallback(builder.build(),
new ConnectivityManager.NetworkCallback() {
@Override
public void onCapabilitiesChanged(Network network, NetworkCapabilities cap) {
Message message = handler.obtainMessage();
message.obj = "New downlink capacity received: " +
cap.getLinkDownstreamBandwidthKbps() + " kbps on network: "
+ network.toString() + "\n";
handler.sendMessage(message);
}
});
// Regsiter button action callback function, which pulls the LCE service
// for bandwidth update.
final Button button = (Button) findViewById(R.id.lceButton);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
for(Network network : connectityManager.getAllNetworks()) {
// No-op for network interface not supporting LCE.
connectityManager.requestBandwidthUpdate(network);
}
}
});
}
}