Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #849 by caching previous states #880

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions AIMSICD/src/main/java/com/secupwn/aimsicd/data/DeviceUpdate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package com.secupwn.aimsicd.data;

import com.secupwn.aimsicd.R;
import com.secupwn.aimsicd.service.AimsicdService;
import com.secupwn.aimsicd.utils.Device;

/**
* Created by Kai on 2016/6/3.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use the @author javadoc-tag here

*/

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the empty line here

public class DeviceUpdate {
private static DeviceUpdate lastUpdate;

public static DeviceUpdate getLastUpdate() {
return lastUpdate;
}

public static DeviceUpdate getUpdate(AimsicdService mAimsicdService) {
mAimsicdService.getCellTracker().refreshDevice();
String notAvailable = mAimsicdService.getApplicationContext().getString(R.string.n_a);
lastUpdate = new DeviceUpdate();
Device mDevice = mAimsicdService.getCellTracker().getDevice();
lastUpdate.phoneId = mDevice.getPhoneId();
lastUpdate.locationAreaCode = String.valueOf(mAimsicdService.getCell().getLocationAreaCode());
lastUpdate.cellId = String.valueOf(mAimsicdService.getCell().getCellId());
lastUpdate.systemId = String.valueOf(mAimsicdService.getCell().getSid());
lastUpdate.lteTimingAdvanceInt = mAimsicdService.getCell().getTimingAdvance();
lastUpdate.lteTimingAdvance = String.valueOf(lastUpdate.lteTimingAdvanceInt);
lastUpdate.primaryScramblingCodeInt = mAimsicdService.getCell().getPrimaryScramblingCode();
lastUpdate.primaryScramblingCode = String.valueOf(lastUpdate.primaryScramblingCodeInt);
lastUpdate.simCountry = mDevice.getSimCountry().orElse(notAvailable);
lastUpdate.simOperatorId = mDevice.getSimOperator().orElse(notAvailable);
lastUpdate.simOperatorName = mDevice.getSimOperatorName().orElse(notAvailable);
lastUpdate.simImsi = mDevice.getSimSubs().orElse(notAvailable);
lastUpdate.simSerial = mDevice.getSimSerial().orElse(notAvailable);
lastUpdate.deviceType = mDevice.getPhoneType();
lastUpdate.deviceImei = mDevice.getIMEI();
lastUpdate.deviceImeiVersion = mDevice.getIMEIv();
lastUpdate.networkName = mDevice.getNetworkName();
lastUpdate.networkCode = mDevice.getMncMcc();
lastUpdate.networkType = mDevice.getNetworkTypeName();
lastUpdate.dataActivityType = mDevice.getDataActivityType();
lastUpdate.dataStatus = mDevice.getDataState();
lastUpdate.networkRoaming = String.valueOf(mDevice.isRoaming());
return getLastUpdate();
}

private DeviceUpdate() {
}

private String locationAreaCode;
private String cellId;
private String systemId;
private String lteTimingAdvance;
private int lteTimingAdvanceInt;
private String primaryScramblingCode;
private int primaryScramblingCodeInt;
private String simCountry;
private String simOperatorId;
private String simOperatorName;
private String simImsi;
private String simSerial;
private String deviceType;
private String deviceImei;
private String deviceImeiVersion;
private String networkName;
private String networkCode;
private String networkType;
private String dataActivityType;
private String dataStatus;
private String networkRoaming;
private int phoneId;

public String getLocationAreaCode() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use lombok's @Getter for all the getters

return locationAreaCode;
}

public String getCellId() {
return cellId;
}

public String getSystemId() {
return systemId;
}

public String getLteTimingAdvance() {
return lteTimingAdvance;
}

public int getLteTimingAdvanceInt() {
return lteTimingAdvanceInt;
}

public String getPrimaryScramblingCode() {
return primaryScramblingCode;
}

public int getPrimaryScramblingCodeInt() {
return primaryScramblingCodeInt;
}

public String getSimCountry() {
return simCountry;
}

public String getSimOperatorId() {
return simOperatorId;
}

public String getSimOperatorName() {
return simOperatorName;
}

public String getSimImsi() {
return simImsi;
}

public String getSimSerial() {
return simSerial;
}

public String getDeviceType() {
return deviceType;
}

public String getDeviceImei() {
return deviceImei;
}

public String getDeviceImeiVersion() {
return deviceImeiVersion;
}

public String getNetworkName() {
return networkName;
}

public String getNetworkCode() {
return networkCode;
}

public String getNetworkType() {
return networkType;
}

public String getDataActivityType() {
return dataActivityType;
}

public String getDataStatus() {
return dataStatus;
}

public String getNetworkRoaming() {
return networkRoaming;
}

public int getPhoneId() {
return phoneId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@

import com.kaichunlin.transition.animation.AnimationManager;
import com.secupwn.aimsicd.R;
import com.secupwn.aimsicd.data.DeviceUpdate;
import com.secupwn.aimsicd.service.AimsicdService;
import com.secupwn.aimsicd.service.CellTracker;
import com.secupwn.aimsicd.ui.widget.HighlightTextView;
import com.secupwn.aimsicd.utils.Cell;
import com.secupwn.aimsicd.utils.Device;
import com.secupwn.aimsicd.utils.Helpers;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.OkHttpClient;
Expand Down Expand Up @@ -138,12 +138,18 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
public void onResume() {
super.onResume();

if (!mBound) {
DeviceUpdate deviceUpdate = DeviceUpdate.getLastUpdate();
if (deviceUpdate != null) {
updateUI(deviceUpdate, false);
}
if (mBound) {
swipeRefreshLayout.setRefreshing(true);
onRefresh();
} else {
// Bind to LocalService
Intent intent = new Intent(mContext, AimsicdService.class);
mContext.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}
updateUI();
}

@Override
Expand All @@ -170,7 +176,7 @@ public void onServiceConnected(ComponentName name, IBinder service) {
// We've bound to LocalService, cast the IBinder and get LocalService instance
mAimsicdService = ((AimsicdService.AimscidBinder) service).getService();
mBound = true;
updateUI();
updateUI(DeviceUpdate.getUpdate(mAimsicdService), true);
}

@Override
Expand All @@ -180,70 +186,75 @@ public void onServiceDisconnected(ComponentName arg0) {
}
};

private void updateUI() {
if (mBound) {
final AnimationManager ani = new AnimationManager();
private void updateHighlightTextView(HighlightTextView view, String value, boolean animate, AnimationManager ani) {
if (animate) {
view.updateText(value, ani);
} else {
view.setText(value);
}
}

mAimsicdService.getCellTracker().refreshDevice();
Device mDevice = mAimsicdService.getCellTracker().getDevice();
switch (mDevice.getPhoneId()) {
private void updateUI(DeviceUpdate deviceUpdate, boolean animate) {
if (!animate || mBound) {
final AnimationManager ani = animate ? new AnimationManager() : null;

switch (deviceUpdate.getPhoneId()) {
case TelephonyManager.PHONE_TYPE_NONE: // Maybe bad!
case TelephonyManager.PHONE_TYPE_SIP: // Maybe bad!
case TelephonyManager.PHONE_TYPE_GSM: {
locationAreaCodeView.updateText(String.valueOf(mAimsicdService.getCell().getLocationAreaCode()), ani);
updateHighlightTextView(locationAreaCodeView, deviceUpdate.getLocationAreaCode(), animate, ani);
gsmCellIdTableRow.setVisibility(View.VISIBLE);
cellIdView.updateText(String.valueOf(mAimsicdService.getCell().getCellId()), ani);
updateHighlightTextView(cellIdView, deviceUpdate.getCellId(), animate, ani);
break;
}

case TelephonyManager.PHONE_TYPE_CDMA: {
cdmaNetworkIdRow.setVisibility(View.VISIBLE);
networkIdView.updateText(String.valueOf(mAimsicdService.getCell().getLocationAreaCode()), ani);
updateHighlightTextView(networkIdView, deviceUpdate.getLocationAreaCode(), animate, ani);

cdmaSystemIdRow.setVisibility(View.VISIBLE);
systemIdView.updateText(String.valueOf(mAimsicdService.getCell().getSid()), ani);
updateHighlightTextView(systemIdView, deviceUpdate.getSystemId(), animate, ani);

cdmaBaseIdRow.setVisibility(View.VISIBLE);
baseIdView.updateText(String.valueOf(mAimsicdService.getCell().getCellId()), ani);
updateHighlightTextView(baseIdView, deviceUpdate.getCellId(), animate, ani);
break;
}
default:
log.error("unknown phone type: " + mDevice.getPhoneId());
log.error("unknown phone type: " + deviceUpdate.getPhoneId());
}

if (mAimsicdService.getCell().getTimingAdvance() != Integer.MAX_VALUE) {
if (deviceUpdate.getLteTimingAdvanceInt() != Integer.MAX_VALUE) {
lteTimingAdvanceRow.setVisibility(View.VISIBLE);
lteTimingAdvanceView.updateText(String.valueOf(mAimsicdService.getCell().getTimingAdvance()), ani);
updateHighlightTextView(lteTimingAdvanceView, deviceUpdate.getLteTimingAdvance(), animate, ani);
} else {
lteTimingAdvanceRow.setVisibility(View.GONE);
}

if (mAimsicdService.getCell().getPrimaryScramblingCode() != Integer.MAX_VALUE) {
primaryScramblingCodeView.updateText(String.valueOf(mAimsicdService.getCell().getPrimaryScramblingCode()), ani);
if (deviceUpdate.getPrimaryScramblingCodeInt() != Integer.MAX_VALUE) {
updateHighlightTextView(primaryScramblingCodeView, deviceUpdate.getPrimaryScramblingCode(), animate, ani);
primaryScramblingCodeRow.setVisibility(View.VISIBLE);
}

String notAvailable = getString(R.string.n_a);

simCountryView.updateText(mDevice.getSimCountry().orElse(notAvailable), ani);
simOperatorIdView.updateText(mDevice.getSimOperator().orElse(notAvailable), ani);
simOperatorNameView.updateText(mDevice.getSimOperatorName().orElse(notAvailable), ani);
simImsiView.updateText(mDevice.getSimSubs().orElse(notAvailable), ani);
simSerialView.updateText(mDevice.getSimSerial().orElse(notAvailable), ani);

deviceTypeView.updateText(mDevice.getPhoneType(), ani);
deviceImeiView.updateText(mDevice.getIMEI(), ani);
deviceImeiVersionView.updateText(mDevice.getIMEIv(), ani);
networkNameView.updateText(mDevice.getNetworkName(), ani);
networkCodeView.updateText(mDevice.getMncMcc(), ani);
networkTypeView.updateText(mDevice.getNetworkTypeName(), ani);

dataActivityTypeView.updateText(mDevice.getDataActivityType(), ani);
dataStatusView.updateText(mDevice.getDataState(), ani);
networkRoamingView.updateText(String.valueOf(mDevice.isRoaming()), ani);

ani.startAnimation(5000);
updateHighlightTextView(simCountryView, deviceUpdate.getSimCountry(), animate, ani);
updateHighlightTextView(simOperatorIdView, deviceUpdate.getSimOperatorId(), animate, ani);
updateHighlightTextView(simOperatorNameView, deviceUpdate.getSimOperatorName(), animate, ani);
updateHighlightTextView(simImsiView, deviceUpdate.getSimImsi(), animate, ani);
updateHighlightTextView(simSerialView, deviceUpdate.getSimSerial(), animate, ani);

updateHighlightTextView(deviceTypeView, deviceUpdate.getDeviceType(), animate, ani);
updateHighlightTextView(deviceImeiView, deviceUpdate.getDeviceImei(), animate, ani);
updateHighlightTextView(deviceImeiVersionView, deviceUpdate.getDeviceImeiVersion(), animate, ani);
updateHighlightTextView(networkNameView, deviceUpdate.getNetworkName(), animate, ani);
updateHighlightTextView(networkCodeView, deviceUpdate.getNetworkCode(), animate, ani);
updateHighlightTextView(networkTypeView, deviceUpdate.getNetworkType(), animate, ani);

updateHighlightTextView(dataActivityTypeView, deviceUpdate.getDataActivityType(), animate, ani);
updateHighlightTextView(dataStatusView, deviceUpdate.getDataStatus(), animate, ani);
updateHighlightTextView(networkRoamingView, deviceUpdate.getNetworkRoaming(), animate, ani);

if (animate) {
ani.startAnimation(5000);
}
}
}

Expand Down Expand Up @@ -336,7 +347,7 @@ private void processFinish(Cell cell) {
if (cell.isValid()) {
mAimsicdService.setCell(cell);
Helpers.msgShort(mContext, getActivity().getString(R.string.refreshed_cell_id_info)); // TODO re-translating other languages
updateUI();
updateUI(DeviceUpdate.getUpdate(mAimsicdService), true);
swipeRefreshLayout.setRefreshing(false);
}
}
Expand All @@ -345,5 +356,6 @@ private void processFinish(Cell cell) {
private void refreshFailed() {
Helpers.msgShort(mContext, "Failed to refresh CellId. Check network connection.");
swipeRefreshLayout.setRefreshing(false);
updateUI(DeviceUpdate.getUpdate(mAimsicdService), true);
}
}