// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov. // Jad home page: http://www.geocities.com/kpdus/jad.html // Decompiler options: braces fieldsfirst space lnc package com.oliodevices.assist.app.detectors; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.location.Location; import android.os.Bundle; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.PendingResult; import com.google.android.gms.common.api.Result; import com.google.android.gms.common.api.ResultCallback; import com.google.android.gms.common.api.Status; import com.google.android.gms.location.FusedLocationProviderApi; import com.google.android.gms.location.Geofence; import com.google.android.gms.location.GeofencingApi; import com.google.android.gms.location.GeofencingEvent; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; import com.olio.data.object.context.PersonalAssistantContext; import com.olio.data.object.location.OlioLocation; import com.olio.data.object.user.Locations; import com.olio.olios.detector.ManagedDetector; import com.olio.util.ALog; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; public class LocationDetector implements ManagedDetector, com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks, com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener, ResultCallback { public static final String BROADCAST_FILTER = "com.olio.detector:LOCATION_DETECTOR_CMD"; public static final int COMMAND_UPDATE_FENCE = 3; public static final int COMMAND_UPDATE_LOCATION = 4; public static final int COMMAND_UPDATE_LOCATION_LIST = 5; public static final int ERROR = 0; public static final String EXTRA_OLIO_COMMAND = "OLIO_COMMAND"; public static final int LOCATION_RADIUS = 100; private static final Object mPendingCommandsLock = new Object(); private final Context mContext; private PendingIntent mGeoFencePendingIntent; private ArrayList mGeoFences; private GoogleApiClient mGoogleApiClient; private Location mLastKnownLocation; private ArrayList mPendingCommands; private boolean mPendingCurrentContextReport; private BroadcastReceiver mReceiver; private boolean mStarted; public LocationDetector(Context context) { mPendingCommands = new ArrayList(); mReceiver = new BroadcastReceiver() { final LocationDetector this$0; public void onReceive(Context context1, Intent intent) { switch (intent.getIntExtra("OLIO_COMMAND", 0)) { default: return; case 3: // '\003' queueCommand(intent. new Runnable() { final _cls1 this$1; final Intent val$intent; public void run() { onCommandGeoFence(intent); } { this$1 = final__pcls1; intent = Intent.this; super(); } }); return; case 4: // '\004' queueCommand(new Runnable() { final _cls1 this$1; public void run() { onCommandLocation(); } { this$1 = _cls1.this; super(); } }); return; case 5: // '\005' queueCommand(new Runnable() { final _cls1 this$1; public void run() { registerGeoFences(); findCurrentContext(); } { this$1 = _cls1.this; super(); } }); break; } } { this$0 = LocationDetector.this; super(); } }; mContext = context; } private void findCurrentContext() { Location location; Object obj; if (mLastKnownLocation == null) { OlioLocation oliolocation = OlioLocation.olioLocation(mContext.getContentResolver()); if (oliolocation.getLatitude() == null || oliolocation.getLongitude() == null) { return; } mLastKnownLocation = new Location("history"); mLastKnownLocation.setLatitude(Double.parseDouble(oliolocation.getLatitude())); mLastKnownLocation.setLongitude(Double.parseDouble(oliolocation.getLongitude())); mPendingCurrentContextReport = true; } else { mPendingCurrentContextReport = false; } obj = Locations.get(mContext.getContentResolver()).getLocations(); location = new Location("custom"); for (obj = ((Map) (obj)).entrySet().iterator(); ((Iterator) (obj)).hasNext();) { java.util.Map.Entry entry = (java.util.Map.Entry)((Iterator) (obj)).next(); com.olio.data.object.user.Location location1 = (com.olio.data.object.user.Location)entry.getValue(); double d = location1.getLongitude(); location.setLatitude(location1.getLatitude()); location.setLongitude(d); if (mLastKnownLocation.distanceTo(location) < 100F) { onEnterLocation((String)entry.getKey()); return; } } onExitLocation(); } private GoogleApiClient getApiClient() { if (mGoogleApiClient == null) { mGoogleApiClient = (new com.google.android.gms.common.api.GoogleApiClient.Builder(mContext)).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(LocationServices.API).build(); } return mGoogleApiClient; } private ArrayList getGeoFenceIds() { Object obj = Locations.get(mContext.getContentResolver()).getLocations(); ArrayList arraylist = new ArrayList(((Map) (obj)).size()); for (obj = ((Map) (obj)).values().iterator(); ((Iterator) (obj)).hasNext(); arraylist.add(((com.olio.data.object.user.Location)((Iterator) (obj)).next()).getDisplayName())) { } return arraylist; } private PendingIntent getGeoFencePendingIntent() { if (mGeoFencePendingIntent != null) { return mGeoFencePendingIntent; } else { Object obj = new Intent("com.olio.detector:LOCATION_DETECTOR_CMD"); ((Intent) (obj)).putExtra("OLIO_COMMAND", 3); obj = PendingIntent.getBroadcast(mContext, 0, ((Intent) (obj)), 0x8000000); mGeoFencePendingIntent = ((PendingIntent) (obj)); return ((PendingIntent) (obj)); } } private ArrayList getGeoFences() { Object obj = Locations.get(mContext.getContentResolver()).getLocations(); if (obj == null) { return new ArrayList(); } int i = ((Map) (obj)).size(); Object obj1; if (mGeoFences == null) { mGeoFences = new ArrayList(i); } else { mGeoFences.clear(); } for (obj = ((Map) (obj)).values().iterator(); ((Iterator) (obj)).hasNext(); mGeoFences.add(obj1)) { obj1 = (com.olio.data.object.user.Location)((Iterator) (obj)).next(); obj1 = (new com.google.android.gms.location.Geofence.Builder()).setRequestId(((com.olio.data.object.user.Location) (obj1)).getDisplayName()).setCircularRegion(((com.olio.data.object.user.Location) (obj1)).getLatitude(), ((com.olio.data.object.user.Location) (obj1)).getLongitude(), 100F).setExpirationDuration(-1L).setTransitionTypes(3).build(); } return mGeoFences; } private PendingIntent getLocationPendingIntent() { if (mGeoFencePendingIntent != null) { return mGeoFencePendingIntent; } else { Object obj = new Intent("com.olio.detector:LOCATION_DETECTOR_CMD"); ((Intent) (obj)).putExtra("OLIO_COMMAND", 4); obj = PendingIntent.getBroadcast(mContext, 0, ((Intent) (obj)), 0x8000000); mGeoFencePendingIntent = ((PendingIntent) (obj)); return ((PendingIntent) (obj)); } } private void onCommandEnd() { this; JVM INSTR monitorenter ; boolean flag = mGoogleApiClient.isConnected(); if (flag) goto _L2; else goto _L1 _L1: this; JVM INSTR monitorexit ; return; _L2: ArrayList arraylist; mContext.unregisterReceiver(mReceiver); arraylist = getGeoFenceIds(); if (arraylist == null) { break MISSING_BLOCK_LABEL_65; } if (!arraylist.isEmpty()) { LocationServices.GeofencingApi.removeGeofences(mGoogleApiClient, arraylist).setResultCallback(this); } LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, getLocationPendingIntent()).setResultCallback(this); mGoogleApiClient.disconnect(); if (true) goto _L1; else goto _L3 _L3: Exception exception; exception; throw exception; } private void onCommandGeoFence(Intent intent) { intent = GeofencingEvent.fromIntent(intent); if (!intent.hasError()) goto _L2; else goto _L1 _L1: int i = intent.getErrorCode(); switch (i) { default: ALog.e("Error getting geo-fences: %d", new Object[] { Integer.valueOf(i) }); break; case 0: // '\0' break; } _L4: return; _L2: int j = intent.getGeofenceTransition(); intent = intent.getTriggeringGeofences(); switch (j) { default: return; case 1: // '\001' int k = 0; while (k < intent.size()) { onEnterLocation(((Geofence)intent.get(k)).getRequestId()); k++; } break; case 2: // '\002' onExitLocation(); return; } if (true) goto _L4; else goto _L3 _L3: } private void onCommandLocation() { mLastKnownLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); if (mLastKnownLocation != null) { (new OlioLocation(String.valueOf(mLastKnownLocation.getLatitude()), String.valueOf(mLastKnownLocation.getLongitude()))).save(mContext.getContentResolver()); if (mPendingCurrentContextReport) { findCurrentContext(); } } } private void onCommandStart() { this; JVM INSTR monitorenter ; if (!mGoogleApiClient.isConnected()) goto _L2; else goto _L1 _L1: boolean flag = mGoogleApiClient.isConnecting(); if (!flag) goto _L3; else goto _L2 _L2: this; JVM INSTR monitorexit ; return; _L3: mContext.registerReceiver(mReceiver, new IntentFilter("com.olio.detector:LOCATION_DETECTOR_CMD")); registerLocationUpdateAndGetCurrentLocation(); registerGeoFences(); findCurrentContext(); if (true) goto _L2; else goto _L4 _L4: Exception exception; exception; throw exception; } private void onEnterLocation(String s) { mPendingCurrentContextReport = false; updateLocationTag(s); } private void onExitLocation() { mPendingCurrentContextReport = false; updateLocationTag("unknown"); } private void queueCommand(Runnable runnable) { GoogleApiClient googleapiclient = getApiClient(); if (!googleapiclient.isConnected()) { synchronized (mPendingCommandsLock) { mPendingCommands.add(runnable); } if (!googleapiclient.isConnecting()) { googleapiclient.connect(); } return; } else { runnable.run(); return; } runnable; obj; JVM INSTR monitorexit ; throw runnable; } private void registerGeoFences() { Object obj = getGeoFences(); if (((ArrayList) (obj)).isEmpty()) { return; } else { obj = (new com.google.android.gms.location.GeofencingRequest.Builder()).setInitialTrigger(4).addGeofences(((List) (obj))).build(); LocationServices.GeofencingApi.addGeofences(mGoogleApiClient, ((com.google.android.gms.location.GeofencingRequest) (obj)), getGeoFencePendingIntent()).setResultCallback(this); return; } } private void registerLocationUpdateAndGetCurrentLocation() { mLastKnownLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); if (mLastKnownLocation != null) { (new OlioLocation(String.valueOf(mLastKnownLocation.getLatitude()), String.valueOf(mLastKnownLocation.getLongitude()))).save(mContext.getContentResolver()); } LocationRequest locationrequest = new LocationRequest(); locationrequest.setInterval(0x7fffffffffffffffL); locationrequest.setSmallestDisplacement(5000F); locationrequest.setFastestInterval(0x36ee80L); locationrequest.setPriority(104); LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, locationrequest, getLocationPendingIntent()); } private void updateLocationTag(String s) { android.content.ContentResolver contentresolver = mContext.getContentResolver(); PersonalAssistantContext personalassistantcontext = PersonalAssistantContext.personalAssistantContext(contentresolver, "location"); if (personalassistantcontext == null) { (new PersonalAssistantContext("location", s)).save(contentresolver); return; } else { personalassistantcontext.setContextValue(s); personalassistantcontext.save(contentresolver); return; } } public void onConnected(Bundle bundle) { onCommandStart(); mStarted = true; ArrayList arraylist; synchronized (mPendingCommandsLock) { arraylist = new ArrayList(mPendingCommands); mPendingCommands.clear(); } for (bundle = arraylist.iterator(); bundle.hasNext(); ((Runnable)bundle.next()).run()) { } break MISSING_BLOCK_LABEL_72; exception; bundle; JVM INSTR monitorexit ; throw exception; } public void onConnectionFailed(ConnectionResult connectionresult) { ALog.d("Google Api connection failed", new Object[0]); } public void onConnectionSuspended(int i) { ALog.d("Google Api Connection Suspended", new Object[0]); } public void onDisconnect() { } public volatile void onResult(Result result) { onResult((Status)result); } public void onResult(Status status) { ALog.d("Service status message: %s", new Object[] { status.getStatusMessage() }); } public void register() { GoogleApiClient googleapiclient = getApiClient(); if (!mStarted && !googleapiclient.isConnecting()) { googleapiclient.connect(); } } public boolean shouldUpdate() { return false; } public void unregister() { queueCommand(new Runnable() { final LocationDetector this$0; public void run() { onCommandEnd(); mStarted = false; } { this$0 = LocationDetector.this; super(); } }); } public void update() { } public Long updateFrequency() { return null; } public boolean updateOnReconnect() { return false; } /* static boolean access$602(LocationDetector locationdetector, boolean flag) { locationdetector.mStarted = flag; return flag; } */ }