summaryrefslogtreecommitdiff
authorTing Li <ting.li@amlogic.com>2017-09-05 05:44:16 (GMT)
committer Ting Li <ting.li@amlogic.com>2017-09-05 05:57:05 (GMT)
commit7f7fba084ed5c04ec4dff75365cef9bffa81ab1d (patch)
treeabba5cdb10e891419164d0a39d60cd4fdf203c14
parentc3e193c09de04b8ef68d059dc634e49512c71d8e (diff)
downloadOTAUpgrade2-7f7fba084ed5c04ec4dff75365cef9bffa81ab1d.zip
OTAUpgrade2-7f7fba084ed5c04ec4dff75365cef9bffa81ab1d.tar.gz
OTAUpgrade2-7f7fba084ed5c04ec4dff75365cef9bffa81ab1d.tar.bz2
otaupgrade: use service to receive connectivity_change broadcast [1/2]
PD#150024 use ABCheckUpService to receive connectivity_change broadcast, this is an ineffective function in non-ab system. Change-Id: Ia80b6564def1eaf6e4d91d99505ba9eefe1117c4
Diffstat
-rw-r--r--src/com/droidlogic/otaupgrade/ABCheckUpService.java48
-rw-r--r--src/com/droidlogic/otaupgrade/LoaderReceiver.java17
-rw-r--r--src/com/droidlogic/otaupgrade/UpdateEngineCallback.java9
3 files changed, 41 insertions, 33 deletions
diff --git a/src/com/droidlogic/otaupgrade/ABCheckUpService.java b/src/com/droidlogic/otaupgrade/ABCheckUpService.java
index 635a11c..68ed349 100644
--- a/src/com/droidlogic/otaupgrade/ABCheckUpService.java
+++ b/src/com/droidlogic/otaupgrade/ABCheckUpService.java
@@ -28,6 +28,7 @@ import java.net.URLConnection;
import com.amlogic.update.util.UpgradeInfo;
import com.amlogic.update.util.PrefUtil;
import android.app.Service;
+import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -37,7 +38,10 @@ import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.util.Log;
-
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.net.wifi.WifiManager;
+import android.os.Bundle;
public class ABCheckUpService extends Service {
private static String TAG = "ABCheckUpService";
private HandlerThread mRCThread;
@@ -48,14 +52,20 @@ public class ABCheckUpService extends Service {
public static final String REASON_UPDATE = "update";
public static final String REASON_COMPLETE = "complete";
private boolean download = false;
-
+ private PrefUtils mPref;
+ private BroadcastReceiver mReceiver;
@Override
public void onCreate() {
super.onCreate();
mRCThread = new HandlerThread("update");
mRCThread.start();
mRCHandler = new Handler(mRCThread.getLooper());
-
+ mPref = new PrefUtils ( this );
+ mReceiver = new ConnectReceiver();
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
+ this.registerReceiver(mReceiver, filter);
+ UpgradeInfo update = new UpgradeInfo(this);
}
@Override
@@ -154,28 +164,36 @@ public class ABCheckUpService extends Service {
@Override
public void onDestroy() {
Log.d(TAG,"onDestroy..............");
+ unregisterReceiver(mReceiver);
if ( mRCThread != null ) {
mRCThread.quitSafely();
mRCThread = null;
}
}
-
+ class ConnectReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive ( Context context, Intent intent ) {
+ if ( ( ConnectivityManager.CONNECTIVITY_ACTION ).equals ( intent.getAction() ) ) {
+ Bundle bundle = intent.getExtras();
+ NetworkInfo netInfo = ( NetworkInfo )bundle.getParcelable( WifiManager.EXTRA_NETWORK_INFO);
+ if ( mPref.getBooleanVal ( "Boot_Checked", false ) &&
+ ( netInfo != null ) &&
+ ( netInfo.getDetailedState() == NetworkInfo.DetailedState.CONNECTED ) ) {
+ mPref.setBoolean ( "Boot_Checked", false );
+ mRCHandler.post(update);
+ }
+ }
+ }
+ }
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
- UpgradeInfo info =new UpgradeInfo(ABCheckUpService.this);
- String reason = intent.getStringExtra(REASON);
- Log.d(TAG,"onStartCommand.............."+reason);
- if ( reason != null && reason.equals(REASON_COMPLETE) ) {
- String ab_update = UpgradeInfo.getString(AB_UPDATE);
- if ( ab_update.equalsIgnoreCase("true") ) {
- disableOTA(true);
- } else {
- disableOTA(false);
- }
+ String ab_update = UpgradeInfo.getString(AB_UPDATE);
+ if ( ab_update.equalsIgnoreCase("true") ) {
+ disableOTA(true);
} else {
- mRCHandler.post(update);
+ disableOTA(false);
}
return START_NOT_STICKY;
}
diff --git a/src/com/droidlogic/otaupgrade/LoaderReceiver.java b/src/com/droidlogic/otaupgrade/LoaderReceiver.java
index 62663c1..2402dbf 100644
--- a/src/com/droidlogic/otaupgrade/LoaderReceiver.java
+++ b/src/com/droidlogic/otaupgrade/LoaderReceiver.java
@@ -77,7 +77,6 @@ public class LoaderReceiver extends BroadcastReceiver {
try{
Class abcheckService = Class.forName("com.droidlogic.otaupgrade.ABCheckUpService");
Intent abcheck = new Intent(mContext, abcheckService);
- abcheck.putExtra("reason","complete");
mContext.startService (abcheck);
} catch(ClassNotFoundException ex) {
//ex.printStackTrace();
@@ -108,25 +107,13 @@ public class LoaderReceiver extends BroadcastReceiver {
if ( mPref.getBooleanVal ( "Boot_Checked", false ) &&
( netInfo != null ) &&
( netInfo.getDetailedState() == NetworkInfo.DetailedState.CONNECTED ) ) {
- mPref.setBoolean ( "Boot_Checked", false );
- if ( mPref.getBooleanVal ( PrefUtils.PREF_AUTO_CHECK, false ) ) {
- mContext.startService ( new Intent (
- UpdateService.ACTION_AUTOCHECK ) );
- return;
- } else if ( ( "true" ).equals ( PrefUtils.getProperties (
+ if ( mPref.getBooleanVal ( PrefUtils.PREF_AUTO_CHECK, false ) ||( "true" ).equals ( PrefUtils.getProperties (
"ro.product.update.autocheck", "false" ) ) ) {
mPref.setBoolean ( PrefUtils.PREF_AUTO_CHECK, true );
+ mPref.setBoolean ( "Boot_Checked", false );
mContext.startService ( new Intent (
UpdateService.ACTION_AUTOCHECK ) );
}
- try{
- Class abcheckService = Class.forName("com.droidlogic.otaupgrade.ABCheckUpService");
- Intent abupdate = new Intent(mContext, abcheckService);
- abupdate.putExtra("reason","update");
- mContext.startService (abupdate);
- } catch(ClassNotFoundException ex) {
- //ex.printStackTrace();
- }
}
}
}
diff --git a/src/com/droidlogic/otaupgrade/UpdateEngineCallback.java b/src/com/droidlogic/otaupgrade/UpdateEngineCallback.java
index fea3056..e83ce22 100644
--- a/src/com/droidlogic/otaupgrade/UpdateEngineCallback.java
+++ b/src/com/droidlogic/otaupgrade/UpdateEngineCallback.java
@@ -61,10 +61,12 @@ public class UpdateEngineCallback extends IUpdateEngineCallback.Stub{
public void dispatchMessage(Message msg) {
switch ( msg.what ) {
case MSG_SHOWPROGRESS:
- showProgress();
+ if (!isShowing)
+ showProgress();
break;
case MSG_HIDEPROGRESS:
- hideProgress();
+ if (isShowing)
+ hideProgress();
break;
case MSG_UPDATEPROCESS:
mBar.setProgress(msg.arg1);
@@ -143,7 +145,8 @@ public class UpdateEngineCallback extends IUpdateEngineCallback.Stub{
private void hideProgress() {
isShowing = false;
Log.d(TAG,"hideprogress");
- mWindowManager.removeView(rootView);
+ if ( rootView != null && rootView.isShown())
+ mWindowManager.removeView(rootView);
}
}