| OLD | NEW |
| 1 // Copyright 2015 Google Inc. All Rights Reserved. | 1 // Copyright 2015 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 package org.chromium.customtabsclient; | 15 package org.chromium.customtabsclient; |
| 16 | 16 |
| 17 import android.app.Activity; | 17 import android.app.Activity; |
| 18 import android.app.ActivityManager; |
| 18 import android.app.ActivityOptions; | 19 import android.app.ActivityOptions; |
| 19 import android.app.PendingIntent; | 20 import android.app.PendingIntent; |
| 20 import android.content.Intent; | 21 import android.content.Intent; |
| 21 import android.content.pm.PackageManager; | 22 import android.content.pm.PackageManager; |
| 22 import android.content.pm.ResolveInfo; | 23 import android.content.pm.ResolveInfo; |
| 23 import android.graphics.Bitmap; | 24 import android.graphics.Bitmap; |
| 24 import android.graphics.BitmapFactory; | 25 import android.graphics.BitmapFactory; |
| 25 import android.graphics.Color; | 26 import android.graphics.Color; |
| 26 import android.media.MediaPlayer; | 27 import android.media.MediaPlayer; |
| 27 import android.net.Uri; | 28 import android.net.Uri; |
| 28 import android.os.Bundle; | 29 import android.os.Bundle; |
| 30 import android.os.Handler; |
| 31 import android.os.Looper; |
| 29 import android.support.customtabs.CustomTabsCallback; | 32 import android.support.customtabs.CustomTabsCallback; |
| 30 import android.support.customtabs.CustomTabsClient; | 33 import android.support.customtabs.CustomTabsClient; |
| 31 import android.support.customtabs.CustomTabsIntent; | 34 import android.support.customtabs.CustomTabsIntent; |
| 32 import android.support.customtabs.CustomTabsServiceConnection; | 35 import android.support.customtabs.CustomTabsServiceConnection; |
| 33 import android.support.customtabs.CustomTabsSession; | 36 import android.support.customtabs.CustomTabsSession; |
| 34 import android.text.TextUtils; | 37 import android.text.TextUtils; |
| 35 import android.util.Log; | 38 import android.util.Log; |
| 36 import android.util.Pair; | 39 import android.util.Pair; |
| 37 import android.view.LayoutInflater; | 40 import android.view.LayoutInflater; |
| 38 import android.view.View; | 41 import android.view.View; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 63 private CustomTabsSession mCustomTabsSession; | 66 private CustomTabsSession mCustomTabsSession; |
| 64 private CustomTabsClient mClient; | 67 private CustomTabsClient mClient; |
| 65 private CustomTabsServiceConnection mConnection; | 68 private CustomTabsServiceConnection mConnection; |
| 66 private String mPackageNameToBind; | 69 private String mPackageNameToBind; |
| 67 private Button mConnectButton; | 70 private Button mConnectButton; |
| 68 private Button mWarmupButton; | 71 private Button mWarmupButton; |
| 69 private Button mMayLaunchButton; | 72 private Button mMayLaunchButton; |
| 70 private Button mLaunchButton; | 73 private Button mLaunchButton; |
| 71 private MediaPlayer mMediaPlayer; | 74 private MediaPlayer mMediaPlayer; |
| 72 | 75 |
| 76 /** |
| 77 * Once per second, asks the framework for the process importance, and logs
any change. |
| 78 */ |
| 79 private Runnable mLogImportance = new Runnable() { |
| 80 private int mPreviousImportance = -1; |
| 81 private boolean mPreviousServiceInUse = false; |
| 82 private Handler mHandler = new Handler(Looper.getMainLooper()); |
| 83 |
| 84 @Override |
| 85 public void run() { |
| 86 ActivityManager.RunningAppProcessInfo state = |
| 87 new ActivityManager.RunningAppProcessInfo(); |
| 88 ActivityManager.getMyMemoryState(state); |
| 89 int importance = state.importance; |
| 90 boolean serviceInUse = state.importanceReasonCode |
| 91 == ActivityManager.RunningAppProcessInfo.REASON_SERVICE_IN_U
SE; |
| 92 if (importance != mPreviousImportance || serviceInUse != mPreviousSe
rviceInUse) { |
| 93 mPreviousImportance = importance; |
| 94 mPreviousServiceInUse = serviceInUse; |
| 95 String message = "New importance = " + importance; |
| 96 if (serviceInUse) message += " (Reason: Service in use)"; |
| 97 Log.w(TAG, message); |
| 98 } |
| 99 mHandler.postDelayed(this, 1000); |
| 100 } |
| 101 }; |
| 102 |
| 73 private static class NavigationCallback extends CustomTabsCallback { | 103 private static class NavigationCallback extends CustomTabsCallback { |
| 74 @Override | 104 @Override |
| 75 public void onNavigationEvent(int navigationEvent, Bundle extras) { | 105 public void onNavigationEvent(int navigationEvent, Bundle extras) { |
| 76 Log.w(TAG, "onNavigationEvent: Code = " + navigationEvent); | 106 Log.w(TAG, "onNavigationEvent: Code = " + navigationEvent); |
| 77 } | 107 } |
| 78 } | 108 } |
| 79 | 109 |
| 80 @Override | 110 @Override |
| 81 protected void onCreate(Bundle savedInstanceState) { | 111 protected void onCreate(Bundle savedInstanceState) { |
| 82 super.onCreate(savedInstanceState); | 112 super.onCreate(savedInstanceState); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 return; | 169 return; |
| 140 } | 170 } |
| 141 mPackageNameToBind = item.second; | 171 mPackageNameToBind = item.second; |
| 142 } | 172 } |
| 143 | 173 |
| 144 @Override | 174 @Override |
| 145 public void onNothingSelected(AdapterView<?> parent) { | 175 public void onNothingSelected(AdapterView<?> parent) { |
| 146 mPackageNameToBind = null; | 176 mPackageNameToBind = null; |
| 147 } | 177 } |
| 148 }); | 178 }); |
| 179 |
| 180 mLogImportance.run(); |
| 149 } | 181 } |
| 150 | 182 |
| 151 @Override | 183 @Override |
| 152 protected void onDestroy() { | 184 protected void onDestroy() { |
| 153 unbindCustomTabsService(); | 185 unbindCustomTabsService(); |
| 154 super.onDestroy(); | 186 super.onDestroy(); |
| 155 } | 187 } |
| 156 | 188 |
| 157 private CustomTabsSession getSession() { | 189 private CustomTabsSession getSession() { |
| 158 if (mClient == null) { | 190 if (mClient == null) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 289 |
| 258 @Override | 290 @Override |
| 259 public void onServiceDisconnected() { | 291 public void onServiceDisconnected() { |
| 260 mConnectButton.setEnabled(true); | 292 mConnectButton.setEnabled(true); |
| 261 mWarmupButton.setEnabled(false); | 293 mWarmupButton.setEnabled(false); |
| 262 mMayLaunchButton.setEnabled(false); | 294 mMayLaunchButton.setEnabled(false); |
| 263 mLaunchButton.setEnabled(false); | 295 mLaunchButton.setEnabled(false); |
| 264 mClient = null; | 296 mClient = null; |
| 265 } | 297 } |
| 266 } | 298 } |
| OLD | NEW |