repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
klaun76/gwt-pixi
src/main/java/sk/mrtn/pixi/client/stage/AResponsiveController.java
// Path: src/main/java/sk/mrtn/pixi/client/Container.java // @JsType(isNative = true, namespace = "PIXI") // public class Container extends DisplayObject { // // /** // * The array of children of this container. // */ // @JsProperty // public DisplayObject[] children; // // /** // * The height of the Container, setting this will actually // * modify the scale to achieve the value set // */ // @JsProperty // public double height; // // /** // * The width of the Container, setting this will actually // * modify the scale to achieve the value set // */ // @JsProperty // public double width; // // @Inject // @JsConstructor // public Container(){} // // // PUBLIC METHODS // @JsMethod // public native void onChildrenChange(); // // /** // * Adds a child or multiple children to the container. // * Multple items can be added like so: // * myContainer.addChild(thinkOne, thingTwo, thingThree) // * @param child - repeatable, The DisplayObject(s) to add to the container // * @return The first child that was added. // */ // @JsMethod // public native DisplayObject addChild(DisplayObject... child); // // /** // * Adds a child to the container at a specified index. // * If the index is out of bounds an error will be thrown // * @param child The child to add // * @param index The index to place the child in // * @return The child that was added. // */ // @JsMethod // public native DisplayObject addChildAt(DisplayObject child, int index); // // // /** // * Swaps the position of 2 Display Objects within this container. // * @param child - First display object to swap // * @param child2 - Second display object to swap // */ // @JsMethod // public native void swapChildren(DisplayObject child, DisplayObject child2); // // /** // * TODO:check if can be null // * Returns the index position of a child DisplayObject instance // * @param child The DisplayObject instance to identify // * @return The index position of the child display object to identify // */ // @JsMethod // public native int getChildIndex(DisplayObject child); // // /** // * Changes the position of an existing child in the display object container // * @param child - The child DisplayObject instance for which you want to change the index number // * @param index - The resulting index number for the child display object // */ // @JsMethod // public native void setChildIndex(DisplayObject child, int index); // // /** // * Returns the child at the specified index // * @param index The index to get the child at // * @return The child at the given index, if any. // */ // @JsMethod // public native DisplayObject getChildAt(int index); // // /** // * Removes a child from the container. // * @param child - The DisplayObject to remove // * @return The child that was removed. // */ // @JsMethod // public native DisplayObject removeChild(DisplayObject child); // // /** // * Removes a child from the specified index position. // * @param index - The index to get the child from // * @return The child that was removed. // */ // @JsMethod // public native DisplayObject removeChildAt(int index); // // /** // * TODO:check behavior when parameters omitted, add overload methods // * Removes all children from this container that are within the begin and end indexes. // * @param beginIndex (default 0) The beginning position. // * @param endIndex (this.children.length) The ending position. Default value is size of the container. // */ // @JsMethod // public native void removeChildren(int beginIndex, int endIndex); // @JsMethod // public native Texture generateTexture(Renderer renderer, int resolution, int scaleMode); // // /** // * Removes all internal references and listeners as well // * as removes children from the display list. // * Do not use a Container after calling destroy. // * TODO: test actual functionality and add Typed variable // * @param options // */ // @JsMethod // public native void destroy(Object options); // // @JsMethod // public native DisplayObject getChildByName(String name); // // }
import sk.mrtn.pixi.client.Container; import java.util.ArrayList; import java.util.List;
package sk.mrtn.pixi.client.stage; /** * Created by martinliptak on 02/10/16. */ public abstract class AResponsiveController implements IResponsiveController { private List<IResponsiveController> responsiveControllers;
// Path: src/main/java/sk/mrtn/pixi/client/Container.java // @JsType(isNative = true, namespace = "PIXI") // public class Container extends DisplayObject { // // /** // * The array of children of this container. // */ // @JsProperty // public DisplayObject[] children; // // /** // * The height of the Container, setting this will actually // * modify the scale to achieve the value set // */ // @JsProperty // public double height; // // /** // * The width of the Container, setting this will actually // * modify the scale to achieve the value set // */ // @JsProperty // public double width; // // @Inject // @JsConstructor // public Container(){} // // // PUBLIC METHODS // @JsMethod // public native void onChildrenChange(); // // /** // * Adds a child or multiple children to the container. // * Multple items can be added like so: // * myContainer.addChild(thinkOne, thingTwo, thingThree) // * @param child - repeatable, The DisplayObject(s) to add to the container // * @return The first child that was added. // */ // @JsMethod // public native DisplayObject addChild(DisplayObject... child); // // /** // * Adds a child to the container at a specified index. // * If the index is out of bounds an error will be thrown // * @param child The child to add // * @param index The index to place the child in // * @return The child that was added. // */ // @JsMethod // public native DisplayObject addChildAt(DisplayObject child, int index); // // // /** // * Swaps the position of 2 Display Objects within this container. // * @param child - First display object to swap // * @param child2 - Second display object to swap // */ // @JsMethod // public native void swapChildren(DisplayObject child, DisplayObject child2); // // /** // * TODO:check if can be null // * Returns the index position of a child DisplayObject instance // * @param child The DisplayObject instance to identify // * @return The index position of the child display object to identify // */ // @JsMethod // public native int getChildIndex(DisplayObject child); // // /** // * Changes the position of an existing child in the display object container // * @param child - The child DisplayObject instance for which you want to change the index number // * @param index - The resulting index number for the child display object // */ // @JsMethod // public native void setChildIndex(DisplayObject child, int index); // // /** // * Returns the child at the specified index // * @param index The index to get the child at // * @return The child at the given index, if any. // */ // @JsMethod // public native DisplayObject getChildAt(int index); // // /** // * Removes a child from the container. // * @param child - The DisplayObject to remove // * @return The child that was removed. // */ // @JsMethod // public native DisplayObject removeChild(DisplayObject child); // // /** // * Removes a child from the specified index position. // * @param index - The index to get the child from // * @return The child that was removed. // */ // @JsMethod // public native DisplayObject removeChildAt(int index); // // /** // * TODO:check behavior when parameters omitted, add overload methods // * Removes all children from this container that are within the begin and end indexes. // * @param beginIndex (default 0) The beginning position. // * @param endIndex (this.children.length) The ending position. Default value is size of the container. // */ // @JsMethod // public native void removeChildren(int beginIndex, int endIndex); // @JsMethod // public native Texture generateTexture(Renderer renderer, int resolution, int scaleMode); // // /** // * Removes all internal references and listeners as well // * as removes children from the display list. // * Do not use a Container after calling destroy. // * TODO: test actual functionality and add Typed variable // * @param options // */ // @JsMethod // public native void destroy(Object options); // // @JsMethod // public native DisplayObject getChildByName(String name); // // } // Path: src/main/java/sk/mrtn/pixi/client/stage/AResponsiveController.java import sk.mrtn.pixi.client.Container; import java.util.ArrayList; import java.util.List; package sk.mrtn.pixi.client.stage; /** * Created by martinliptak on 02/10/16. */ public abstract class AResponsiveController implements IResponsiveController { private List<IResponsiveController> responsiveControllers;
protected final Container container;
clementine-player/Android-Remote
app/src/main/java/de/qspool/clementineremote/ui/settings/PreferencesConnection.java
// Path: app/src/main/java/de/qspool/clementineremote/SharedPreferencesKeys.java // public class SharedPreferencesKeys { // // public final static String SP_FIRST_CALL = "first_call"; // // public final static String SP_KEY_IP = "save_clementine_ip"; // // public final static String SP_KEY_AC = "pref_autoconnect"; // // public final static String SP_KEY_USE_VOLUMEKEYS = "pref_volumekey"; // // public final static String SP_KEY_PORT = "pref_port"; // // public final static String SP_LAST_AUTH_CODE = "last_auth_code"; // // public final static String SP_SHOW_TRACKNO = "pref_show_trackno"; // // public final static String SP_LASTFM = "pref_show_lastfm"; // // public final static String SP_KEEP_SCREEN_ON = "pref_keep_screen_on"; // // public final static String SP_WAKE_LOCK = "pref_wake_lock"; // // public final static String SP_LOWER_VOLUME = "pref_lower_volume"; // // public final static String SP_CALL_VOLUME = "pref_call_volume"; // // public final static String SP_VOLUME_INC = "pref_volume_inc"; // // public final static String SP_LIBRARY_GROUPING = "pref_library_grouping"; // // public final static String SP_LIBRARY_SORTING = "pref_library_sorting"; // // public final static String SP_WIFI_ONLY = "pref_dl_wifi_only"; // // public final static String SP_DOWNLOAD_DIR = "pref_dl_dir"; // // public final static String SP_DOWNLOAD_OVERRIDE = "pref_dl_override"; // // public final static String SP_DOWNLOAD_SAVE_OWN_DIR = "pref_dl_pl_save_own_dir"; // // public final static String SP_DOWNLOAD_PLAYLIST_CRT_ARTIST_DIR = "pref_dl_artist_dir"; // // public final static String SP_DOWNLOAD_PLAYLIST_CRT_ALBUM_DIR = "pref_dl_album_dir"; // // public final static String SP_LAST_STACKTRACE = "last_stacktrace"; // // public final static String SP_LAST_SEND_STACKTRACE = "last_send_stacktrace"; // // public final static String SP_LIBRARY_IP = "library_ip"; // // public final static String SP_KNOWN_IP = "known_ips"; // }
import android.content.SharedPreferences; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; import android.widget.Toast; import de.qspool.clementineremote.R; import de.qspool.clementineremote.SharedPreferencesKeys; import de.qspool.clementineremote.backend.Clementine;
/* This file is part of the Android Clementine Remote. * Copyright (C) 2013, Andreas Muttscheller <[email protected]> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package de.qspool.clementineremote.ui.settings; public class PreferencesConnection extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener { private EditTextPreference mPortPreference; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.preference_connection); // Read the port and fill in the summary mPortPreference = (EditTextPreference) getPreferenceScreen()
// Path: app/src/main/java/de/qspool/clementineremote/SharedPreferencesKeys.java // public class SharedPreferencesKeys { // // public final static String SP_FIRST_CALL = "first_call"; // // public final static String SP_KEY_IP = "save_clementine_ip"; // // public final static String SP_KEY_AC = "pref_autoconnect"; // // public final static String SP_KEY_USE_VOLUMEKEYS = "pref_volumekey"; // // public final static String SP_KEY_PORT = "pref_port"; // // public final static String SP_LAST_AUTH_CODE = "last_auth_code"; // // public final static String SP_SHOW_TRACKNO = "pref_show_trackno"; // // public final static String SP_LASTFM = "pref_show_lastfm"; // // public final static String SP_KEEP_SCREEN_ON = "pref_keep_screen_on"; // // public final static String SP_WAKE_LOCK = "pref_wake_lock"; // // public final static String SP_LOWER_VOLUME = "pref_lower_volume"; // // public final static String SP_CALL_VOLUME = "pref_call_volume"; // // public final static String SP_VOLUME_INC = "pref_volume_inc"; // // public final static String SP_LIBRARY_GROUPING = "pref_library_grouping"; // // public final static String SP_LIBRARY_SORTING = "pref_library_sorting"; // // public final static String SP_WIFI_ONLY = "pref_dl_wifi_only"; // // public final static String SP_DOWNLOAD_DIR = "pref_dl_dir"; // // public final static String SP_DOWNLOAD_OVERRIDE = "pref_dl_override"; // // public final static String SP_DOWNLOAD_SAVE_OWN_DIR = "pref_dl_pl_save_own_dir"; // // public final static String SP_DOWNLOAD_PLAYLIST_CRT_ARTIST_DIR = "pref_dl_artist_dir"; // // public final static String SP_DOWNLOAD_PLAYLIST_CRT_ALBUM_DIR = "pref_dl_album_dir"; // // public final static String SP_LAST_STACKTRACE = "last_stacktrace"; // // public final static String SP_LAST_SEND_STACKTRACE = "last_send_stacktrace"; // // public final static String SP_LIBRARY_IP = "library_ip"; // // public final static String SP_KNOWN_IP = "known_ips"; // } // Path: app/src/main/java/de/qspool/clementineremote/ui/settings/PreferencesConnection.java import android.content.SharedPreferences; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; import android.widget.Toast; import de.qspool.clementineremote.R; import de.qspool.clementineremote.SharedPreferencesKeys; import de.qspool.clementineremote.backend.Clementine; /* This file is part of the Android Clementine Remote. * Copyright (C) 2013, Andreas Muttscheller <[email protected]> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package de.qspool.clementineremote.ui.settings; public class PreferencesConnection extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener { private EditTextPreference mPortPreference; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.preference_connection); // Read the port and fill in the summary mPortPreference = (EditTextPreference) getPreferenceScreen()
.findPreference(SharedPreferencesKeys.SP_KEY_PORT);
clementine-player/Android-Remote
app/src/main/java/de/qspool/clementineremote/ui/fragments/playerpages/ConnectionFragment.java
// Path: app/src/main/java/de/qspool/clementineremote/SharedPreferencesKeys.java // public class SharedPreferencesKeys { // // public final static String SP_FIRST_CALL = "first_call"; // // public final static String SP_KEY_IP = "save_clementine_ip"; // // public final static String SP_KEY_AC = "pref_autoconnect"; // // public final static String SP_KEY_USE_VOLUMEKEYS = "pref_volumekey"; // // public final static String SP_KEY_PORT = "pref_port"; // // public final static String SP_LAST_AUTH_CODE = "last_auth_code"; // // public final static String SP_SHOW_TRACKNO = "pref_show_trackno"; // // public final static String SP_LASTFM = "pref_show_lastfm"; // // public final static String SP_KEEP_SCREEN_ON = "pref_keep_screen_on"; // // public final static String SP_WAKE_LOCK = "pref_wake_lock"; // // public final static String SP_LOWER_VOLUME = "pref_lower_volume"; // // public final static String SP_CALL_VOLUME = "pref_call_volume"; // // public final static String SP_VOLUME_INC = "pref_volume_inc"; // // public final static String SP_LIBRARY_GROUPING = "pref_library_grouping"; // // public final static String SP_LIBRARY_SORTING = "pref_library_sorting"; // // public final static String SP_WIFI_ONLY = "pref_dl_wifi_only"; // // public final static String SP_DOWNLOAD_DIR = "pref_dl_dir"; // // public final static String SP_DOWNLOAD_OVERRIDE = "pref_dl_override"; // // public final static String SP_DOWNLOAD_SAVE_OWN_DIR = "pref_dl_pl_save_own_dir"; // // public final static String SP_DOWNLOAD_PLAYLIST_CRT_ARTIST_DIR = "pref_dl_artist_dir"; // // public final static String SP_DOWNLOAD_PLAYLIST_CRT_ALBUM_DIR = "pref_dl_album_dir"; // // public final static String SP_LAST_STACKTRACE = "last_stacktrace"; // // public final static String SP_LAST_SEND_STACKTRACE = "last_send_stacktrace"; // // public final static String SP_LIBRARY_IP = "library_ip"; // // public final static String SP_KNOWN_IP = "known_ips"; // }
import android.annotation.SuppressLint; import android.app.Fragment; import android.content.SharedPreferences; import android.net.TrafficStats; import android.os.Bundle; import android.os.Message; import android.preference.PreferenceManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.SeekBar; import android.widget.TextView; import java.util.Date; import java.util.Locale; import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.TimeUnit; import de.qspool.clementineremote.App; import de.qspool.clementineremote.R; import de.qspool.clementineremote.SharedPreferencesKeys; import de.qspool.clementineremote.backend.pb.ClementineMessage; import de.qspool.clementineremote.backend.pb.ClementineMessageFactory; import de.qspool.clementineremote.ui.interfaces.BackPressHandleable; import de.qspool.clementineremote.ui.interfaces.NameableTitle; import de.qspool.clementineremote.ui.interfaces.RemoteDataReceiver; import de.qspool.clementineremote.utils.Utilities;
/* T his file is part of the Android Clementine Remote. * Copyright (C) 2013, Andreas Muttscheller <[email protected]> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package de.qspool.clementineremote.ui.fragments.playerpages; public class ConnectionFragment extends Fragment implements BackPressHandleable, RemoteDataReceiver, NameableTitle { private TextView tv_ip; private TextView tv_version; private TextView tv_time; private TextView tv_traffic; private SeekBar sb_volume; private SharedPreferences mSharedPref; private Timer mUpdateTimer; private boolean mUserChangesVolume; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Get the shared preferences mSharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); setHasOptionsMenu(true); } @SuppressLint("SetTextI18n") @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_player_connection, container, false); tv_ip = (TextView) view.findViewById(R.id.cn_ip); tv_time = (TextView) view.findViewById(R.id.cn_time); tv_version = (TextView) view.findViewById(R.id.cn_version); tv_traffic = (TextView) view.findViewById(R.id.cn_traffic); updateData();
// Path: app/src/main/java/de/qspool/clementineremote/SharedPreferencesKeys.java // public class SharedPreferencesKeys { // // public final static String SP_FIRST_CALL = "first_call"; // // public final static String SP_KEY_IP = "save_clementine_ip"; // // public final static String SP_KEY_AC = "pref_autoconnect"; // // public final static String SP_KEY_USE_VOLUMEKEYS = "pref_volumekey"; // // public final static String SP_KEY_PORT = "pref_port"; // // public final static String SP_LAST_AUTH_CODE = "last_auth_code"; // // public final static String SP_SHOW_TRACKNO = "pref_show_trackno"; // // public final static String SP_LASTFM = "pref_show_lastfm"; // // public final static String SP_KEEP_SCREEN_ON = "pref_keep_screen_on"; // // public final static String SP_WAKE_LOCK = "pref_wake_lock"; // // public final static String SP_LOWER_VOLUME = "pref_lower_volume"; // // public final static String SP_CALL_VOLUME = "pref_call_volume"; // // public final static String SP_VOLUME_INC = "pref_volume_inc"; // // public final static String SP_LIBRARY_GROUPING = "pref_library_grouping"; // // public final static String SP_LIBRARY_SORTING = "pref_library_sorting"; // // public final static String SP_WIFI_ONLY = "pref_dl_wifi_only"; // // public final static String SP_DOWNLOAD_DIR = "pref_dl_dir"; // // public final static String SP_DOWNLOAD_OVERRIDE = "pref_dl_override"; // // public final static String SP_DOWNLOAD_SAVE_OWN_DIR = "pref_dl_pl_save_own_dir"; // // public final static String SP_DOWNLOAD_PLAYLIST_CRT_ARTIST_DIR = "pref_dl_artist_dir"; // // public final static String SP_DOWNLOAD_PLAYLIST_CRT_ALBUM_DIR = "pref_dl_album_dir"; // // public final static String SP_LAST_STACKTRACE = "last_stacktrace"; // // public final static String SP_LAST_SEND_STACKTRACE = "last_send_stacktrace"; // // public final static String SP_LIBRARY_IP = "library_ip"; // // public final static String SP_KNOWN_IP = "known_ips"; // } // Path: app/src/main/java/de/qspool/clementineremote/ui/fragments/playerpages/ConnectionFragment.java import android.annotation.SuppressLint; import android.app.Fragment; import android.content.SharedPreferences; import android.net.TrafficStats; import android.os.Bundle; import android.os.Message; import android.preference.PreferenceManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.SeekBar; import android.widget.TextView; import java.util.Date; import java.util.Locale; import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.TimeUnit; import de.qspool.clementineremote.App; import de.qspool.clementineremote.R; import de.qspool.clementineremote.SharedPreferencesKeys; import de.qspool.clementineremote.backend.pb.ClementineMessage; import de.qspool.clementineremote.backend.pb.ClementineMessageFactory; import de.qspool.clementineremote.ui.interfaces.BackPressHandleable; import de.qspool.clementineremote.ui.interfaces.NameableTitle; import de.qspool.clementineremote.ui.interfaces.RemoteDataReceiver; import de.qspool.clementineremote.utils.Utilities; /* T his file is part of the Android Clementine Remote. * Copyright (C) 2013, Andreas Muttscheller <[email protected]> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package de.qspool.clementineremote.ui.fragments.playerpages; public class ConnectionFragment extends Fragment implements BackPressHandleable, RemoteDataReceiver, NameableTitle { private TextView tv_ip; private TextView tv_version; private TextView tv_time; private TextView tv_traffic; private SeekBar sb_volume; private SharedPreferences mSharedPref; private Timer mUpdateTimer; private boolean mUserChangesVolume; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Get the shared preferences mSharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); setHasOptionsMenu(true); } @SuppressLint("SetTextI18n") @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_player_connection, container, false); tv_ip = (TextView) view.findViewById(R.id.cn_ip); tv_time = (TextView) view.findViewById(R.id.cn_time); tv_version = (TextView) view.findViewById(R.id.cn_version); tv_traffic = (TextView) view.findViewById(R.id.cn_traffic); updateData();
tv_ip.setText(mSharedPref.getString(SharedPreferencesKeys.SP_KEY_IP, "") + ":" + mSharedPref
clementine-player/Android-Remote
app/src/main/java/de/qspool/clementineremote/backend/downloader/SongDownloaderListener.java
// Path: app/src/main/java/de/qspool/clementineremote/backend/elements/DownloaderResult.java // public class DownloaderResult extends ClementineElement { // // public enum DownloadResult {SUCCESSFUL, INSUFFIANT_SPACE, NOT_MOUNTED, CONNECTION_ERROR, FOBIDDEN, ONLY_WIFI, CANCELLED, ERROR} // // private DownloadResult mResult; // // private int mId; // // public DownloaderResult(int id, DownloadResult result) { // mId = id; // mResult = result; // } // // public DownloadResult getResult() { // return mResult; // } // // public int getId() { // return mId; // } // // /** // * Returns the resource ID for the corresponding errormessage. // * For example CONNECTION_ERROR = Connection error // * // * @return The resource ID for the specific message // */ // public int getMessageStringId() { // switch (mResult) { // case CONNECTION_ERROR: // return R.string.download_noti_canceled; // case FOBIDDEN: // return R.string.download_noti_forbidden; // case INSUFFIANT_SPACE: // return R.string.download_noti_insufficient_space; // case NOT_MOUNTED: // return R.string.download_noti_not_mounted; // case ONLY_WIFI: // return R.string.download_noti_only_wifi; // case SUCCESSFUL: // return R.string.download_noti_complete; // case CANCELLED: // return R.string.download_noti_canceled; // } // // return -1; // } // // }
import de.qspool.clementineremote.backend.elements.DownloaderResult;
/* This file is part of the Android Clementine Remote. * Copyright (C) 2014, Andreas Muttscheller <[email protected]> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package de.qspool.clementineremote.backend.downloader; public interface SongDownloaderListener { public void onProgress(DownloadStatus progress);
// Path: app/src/main/java/de/qspool/clementineremote/backend/elements/DownloaderResult.java // public class DownloaderResult extends ClementineElement { // // public enum DownloadResult {SUCCESSFUL, INSUFFIANT_SPACE, NOT_MOUNTED, CONNECTION_ERROR, FOBIDDEN, ONLY_WIFI, CANCELLED, ERROR} // // private DownloadResult mResult; // // private int mId; // // public DownloaderResult(int id, DownloadResult result) { // mId = id; // mResult = result; // } // // public DownloadResult getResult() { // return mResult; // } // // public int getId() { // return mId; // } // // /** // * Returns the resource ID for the corresponding errormessage. // * For example CONNECTION_ERROR = Connection error // * // * @return The resource ID for the specific message // */ // public int getMessageStringId() { // switch (mResult) { // case CONNECTION_ERROR: // return R.string.download_noti_canceled; // case FOBIDDEN: // return R.string.download_noti_forbidden; // case INSUFFIANT_SPACE: // return R.string.download_noti_insufficient_space; // case NOT_MOUNTED: // return R.string.download_noti_not_mounted; // case ONLY_WIFI: // return R.string.download_noti_only_wifi; // case SUCCESSFUL: // return R.string.download_noti_complete; // case CANCELLED: // return R.string.download_noti_canceled; // } // // return -1; // } // // } // Path: app/src/main/java/de/qspool/clementineremote/backend/downloader/SongDownloaderListener.java import de.qspool.clementineremote.backend.elements.DownloaderResult; /* This file is part of the Android Clementine Remote. * Copyright (C) 2014, Andreas Muttscheller <[email protected]> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package de.qspool.clementineremote.backend.downloader; public interface SongDownloaderListener { public void onProgress(DownloadStatus progress);
public void onDownloadResult(DownloaderResult result);
clementine-player/Android-Remote
app/src/main/java/de/qspool/clementineremote/backend/receivers/ClementinePhoneStateCheck.java
// Path: app/src/main/java/de/qspool/clementineremote/SharedPreferencesKeys.java // public class SharedPreferencesKeys { // // public final static String SP_FIRST_CALL = "first_call"; // // public final static String SP_KEY_IP = "save_clementine_ip"; // // public final static String SP_KEY_AC = "pref_autoconnect"; // // public final static String SP_KEY_USE_VOLUMEKEYS = "pref_volumekey"; // // public final static String SP_KEY_PORT = "pref_port"; // // public final static String SP_LAST_AUTH_CODE = "last_auth_code"; // // public final static String SP_SHOW_TRACKNO = "pref_show_trackno"; // // public final static String SP_LASTFM = "pref_show_lastfm"; // // public final static String SP_KEEP_SCREEN_ON = "pref_keep_screen_on"; // // public final static String SP_WAKE_LOCK = "pref_wake_lock"; // // public final static String SP_LOWER_VOLUME = "pref_lower_volume"; // // public final static String SP_CALL_VOLUME = "pref_call_volume"; // // public final static String SP_VOLUME_INC = "pref_volume_inc"; // // public final static String SP_LIBRARY_GROUPING = "pref_library_grouping"; // // public final static String SP_LIBRARY_SORTING = "pref_library_sorting"; // // public final static String SP_WIFI_ONLY = "pref_dl_wifi_only"; // // public final static String SP_DOWNLOAD_DIR = "pref_dl_dir"; // // public final static String SP_DOWNLOAD_OVERRIDE = "pref_dl_override"; // // public final static String SP_DOWNLOAD_SAVE_OWN_DIR = "pref_dl_pl_save_own_dir"; // // public final static String SP_DOWNLOAD_PLAYLIST_CRT_ARTIST_DIR = "pref_dl_artist_dir"; // // public final static String SP_DOWNLOAD_PLAYLIST_CRT_ALBUM_DIR = "pref_dl_album_dir"; // // public final static String SP_LAST_STACKTRACE = "last_stacktrace"; // // public final static String SP_LAST_SEND_STACKTRACE = "last_send_stacktrace"; // // public final static String SP_LIBRARY_IP = "library_ip"; // // public final static String SP_KNOWN_IP = "known_ips"; // }
import de.qspool.clementineremote.backend.Clementine; import de.qspool.clementineremote.backend.pb.ClementineMessage; import de.qspool.clementineremote.backend.pb.ClementineMessageFactory; import de.qspool.clementineremote.backend.pb.ClementineRemoteProtocolBuffer; import android.Manifest; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.os.Message; import android.preference.PreferenceManager; import android.support.v4.content.ContextCompat; import android.telephony.TelephonyManager; import de.qspool.clementineremote.App; import de.qspool.clementineremote.SharedPreferencesKeys;
/* This file is part of the Android Clementine Remote. * Copyright (C) 2013, Andreas Muttscheller <[email protected]> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package de.qspool.clementineremote.backend.receivers; public class ClementinePhoneStateCheck extends BroadcastReceiver { private static String lastPhoneState = TelephonyManager.EXTRA_STATE_IDLE; @Override public void onReceive(Context context, Intent intent) { if (App.getApp() == null || App.ClementineConnection == null || App.Clementine == null || !App.ClementineConnection.isConnected()) { return; } if (!intent.getAction().equals("android.intent.action.PHONE_STATE")) { return; } if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { return; } // Check if we need to change the volume SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(App.getApp()); String volumeString = prefs
// Path: app/src/main/java/de/qspool/clementineremote/SharedPreferencesKeys.java // public class SharedPreferencesKeys { // // public final static String SP_FIRST_CALL = "first_call"; // // public final static String SP_KEY_IP = "save_clementine_ip"; // // public final static String SP_KEY_AC = "pref_autoconnect"; // // public final static String SP_KEY_USE_VOLUMEKEYS = "pref_volumekey"; // // public final static String SP_KEY_PORT = "pref_port"; // // public final static String SP_LAST_AUTH_CODE = "last_auth_code"; // // public final static String SP_SHOW_TRACKNO = "pref_show_trackno"; // // public final static String SP_LASTFM = "pref_show_lastfm"; // // public final static String SP_KEEP_SCREEN_ON = "pref_keep_screen_on"; // // public final static String SP_WAKE_LOCK = "pref_wake_lock"; // // public final static String SP_LOWER_VOLUME = "pref_lower_volume"; // // public final static String SP_CALL_VOLUME = "pref_call_volume"; // // public final static String SP_VOLUME_INC = "pref_volume_inc"; // // public final static String SP_LIBRARY_GROUPING = "pref_library_grouping"; // // public final static String SP_LIBRARY_SORTING = "pref_library_sorting"; // // public final static String SP_WIFI_ONLY = "pref_dl_wifi_only"; // // public final static String SP_DOWNLOAD_DIR = "pref_dl_dir"; // // public final static String SP_DOWNLOAD_OVERRIDE = "pref_dl_override"; // // public final static String SP_DOWNLOAD_SAVE_OWN_DIR = "pref_dl_pl_save_own_dir"; // // public final static String SP_DOWNLOAD_PLAYLIST_CRT_ARTIST_DIR = "pref_dl_artist_dir"; // // public final static String SP_DOWNLOAD_PLAYLIST_CRT_ALBUM_DIR = "pref_dl_album_dir"; // // public final static String SP_LAST_STACKTRACE = "last_stacktrace"; // // public final static String SP_LAST_SEND_STACKTRACE = "last_send_stacktrace"; // // public final static String SP_LIBRARY_IP = "library_ip"; // // public final static String SP_KNOWN_IP = "known_ips"; // } // Path: app/src/main/java/de/qspool/clementineremote/backend/receivers/ClementinePhoneStateCheck.java import de.qspool.clementineremote.backend.Clementine; import de.qspool.clementineremote.backend.pb.ClementineMessage; import de.qspool.clementineremote.backend.pb.ClementineMessageFactory; import de.qspool.clementineremote.backend.pb.ClementineRemoteProtocolBuffer; import android.Manifest; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.os.Message; import android.preference.PreferenceManager; import android.support.v4.content.ContextCompat; import android.telephony.TelephonyManager; import de.qspool.clementineremote.App; import de.qspool.clementineremote.SharedPreferencesKeys; /* This file is part of the Android Clementine Remote. * Copyright (C) 2013, Andreas Muttscheller <[email protected]> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package de.qspool.clementineremote.backend.receivers; public class ClementinePhoneStateCheck extends BroadcastReceiver { private static String lastPhoneState = TelephonyManager.EXTRA_STATE_IDLE; @Override public void onReceive(Context context, Intent intent) { if (App.getApp() == null || App.ClementineConnection == null || App.Clementine == null || !App.ClementineConnection.isConnected()) { return; } if (!intent.getAction().equals("android.intent.action.PHONE_STATE")) { return; } if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { return; } // Check if we need to change the volume SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(App.getApp()); String volumeString = prefs
.getString(SharedPreferencesKeys.SP_CALL_VOLUME,
clementine-player/Android-Remote
app/src/main/java/de/qspool/clementineremote/backend/ClementinePlayerConnection.java
// Path: app/src/main/java/de/qspool/clementineremote/backend/listener/PlayerConnectionListener.java // public interface PlayerConnectionListener { // // void onConnectionStatusChanged(ClementinePlayerConnection.ConnectionStatus status); // // void onClementineMessageReceived(ClementineMessage clementineMessage); // }
import de.qspool.clementineremote.backend.pb.ClementineRemoteProtocolBuffer.Message.Builder; import de.qspool.clementineremote.backend.pb.ClementineRemoteProtocolBuffer.MsgType; import de.qspool.clementineremote.backend.pb.ClementineRemoteProtocolBuffer.ReasonDisconnect; import de.qspool.clementineremote.backend.pb.ClementineRemoteProtocolBuffer.ResponseDisconnect; import android.net.TrafficStats; import android.os.Handler; import android.os.Looper; import android.os.Message; import java.util.ArrayList; import java.util.Date; import de.qspool.clementineremote.App; import de.qspool.clementineremote.backend.listener.PlayerConnectionListener; import de.qspool.clementineremote.backend.pb.ClementineMessage; import de.qspool.clementineremote.backend.pb.ClementineMessage.ErrorMessage; import de.qspool.clementineremote.backend.pb.ClementineMessageFactory;
/* This file is part of the Android Clementine Remote. * Copyright (C) 2013, Andreas Muttscheller <[email protected]> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package de.qspool.clementineremote.backend; /** * This Thread-Class is used to communicate with Clementine */ public class ClementinePlayerConnection extends ClementineSimpleConnection implements Runnable { public ClementineConnectionHandler mHandler; public final static int PROCESS_PROTOC = 874456; public enum ConnectionStatus {IDLE, CONNECTING, NO_CONNECTION, CONNECTED, LOST_CONNECTION, DISCONNECTED} private final long KEEP_ALIVE_TIMEOUT = 25000; // 25 Second timeout private final int MAX_RECONNECTS = 5; private Handler mUiHandler; private int mLeftReconnects; private long mLastKeepAlive;
// Path: app/src/main/java/de/qspool/clementineremote/backend/listener/PlayerConnectionListener.java // public interface PlayerConnectionListener { // // void onConnectionStatusChanged(ClementinePlayerConnection.ConnectionStatus status); // // void onClementineMessageReceived(ClementineMessage clementineMessage); // } // Path: app/src/main/java/de/qspool/clementineremote/backend/ClementinePlayerConnection.java import de.qspool.clementineremote.backend.pb.ClementineRemoteProtocolBuffer.Message.Builder; import de.qspool.clementineremote.backend.pb.ClementineRemoteProtocolBuffer.MsgType; import de.qspool.clementineremote.backend.pb.ClementineRemoteProtocolBuffer.ReasonDisconnect; import de.qspool.clementineremote.backend.pb.ClementineRemoteProtocolBuffer.ResponseDisconnect; import android.net.TrafficStats; import android.os.Handler; import android.os.Looper; import android.os.Message; import java.util.ArrayList; import java.util.Date; import de.qspool.clementineremote.App; import de.qspool.clementineremote.backend.listener.PlayerConnectionListener; import de.qspool.clementineremote.backend.pb.ClementineMessage; import de.qspool.clementineremote.backend.pb.ClementineMessage.ErrorMessage; import de.qspool.clementineremote.backend.pb.ClementineMessageFactory; /* This file is part of the Android Clementine Remote. * Copyright (C) 2013, Andreas Muttscheller <[email protected]> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package de.qspool.clementineremote.backend; /** * This Thread-Class is used to communicate with Clementine */ public class ClementinePlayerConnection extends ClementineSimpleConnection implements Runnable { public ClementineConnectionHandler mHandler; public final static int PROCESS_PROTOC = 874456; public enum ConnectionStatus {IDLE, CONNECTING, NO_CONNECTION, CONNECTED, LOST_CONNECTION, DISCONNECTED} private final long KEEP_ALIVE_TIMEOUT = 25000; // 25 Second timeout private final int MAX_RECONNECTS = 5; private Handler mUiHandler; private int mLeftReconnects; private long mLastKeepAlive;
private ArrayList<PlayerConnectionListener> mListeners
clementine-player/Android-Remote
app/src/main/java/de/qspool/clementineremote/backend/listener/OnLibraryDownloadListener.java
// Path: app/src/main/java/de/qspool/clementineremote/backend/elements/DownloaderResult.java // public class DownloaderResult extends ClementineElement { // // public enum DownloadResult {SUCCESSFUL, INSUFFIANT_SPACE, NOT_MOUNTED, CONNECTION_ERROR, FOBIDDEN, ONLY_WIFI, CANCELLED, ERROR} // // private DownloadResult mResult; // // private int mId; // // public DownloaderResult(int id, DownloadResult result) { // mId = id; // mResult = result; // } // // public DownloadResult getResult() { // return mResult; // } // // public int getId() { // return mId; // } // // /** // * Returns the resource ID for the corresponding errormessage. // * For example CONNECTION_ERROR = Connection error // * // * @return The resource ID for the specific message // */ // public int getMessageStringId() { // switch (mResult) { // case CONNECTION_ERROR: // return R.string.download_noti_canceled; // case FOBIDDEN: // return R.string.download_noti_forbidden; // case INSUFFIANT_SPACE: // return R.string.download_noti_insufficient_space; // case NOT_MOUNTED: // return R.string.download_noti_not_mounted; // case ONLY_WIFI: // return R.string.download_noti_only_wifi; // case SUCCESSFUL: // return R.string.download_noti_complete; // case CANCELLED: // return R.string.download_noti_canceled; // } // // return -1; // } // // }
import de.qspool.clementineremote.backend.elements.DownloaderResult;
/* This file is part of the Android Clementine Remote. * Copyright (C) 2013, Andreas Muttscheller <[email protected]> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package de.qspool.clementineremote.backend.listener; public interface OnLibraryDownloadListener { void OnProgressUpdate(long progress, int total); void OnOptimizeLibrary();
// Path: app/src/main/java/de/qspool/clementineremote/backend/elements/DownloaderResult.java // public class DownloaderResult extends ClementineElement { // // public enum DownloadResult {SUCCESSFUL, INSUFFIANT_SPACE, NOT_MOUNTED, CONNECTION_ERROR, FOBIDDEN, ONLY_WIFI, CANCELLED, ERROR} // // private DownloadResult mResult; // // private int mId; // // public DownloaderResult(int id, DownloadResult result) { // mId = id; // mResult = result; // } // // public DownloadResult getResult() { // return mResult; // } // // public int getId() { // return mId; // } // // /** // * Returns the resource ID for the corresponding errormessage. // * For example CONNECTION_ERROR = Connection error // * // * @return The resource ID for the specific message // */ // public int getMessageStringId() { // switch (mResult) { // case CONNECTION_ERROR: // return R.string.download_noti_canceled; // case FOBIDDEN: // return R.string.download_noti_forbidden; // case INSUFFIANT_SPACE: // return R.string.download_noti_insufficient_space; // case NOT_MOUNTED: // return R.string.download_noti_not_mounted; // case ONLY_WIFI: // return R.string.download_noti_only_wifi; // case SUCCESSFUL: // return R.string.download_noti_complete; // case CANCELLED: // return R.string.download_noti_canceled; // } // // return -1; // } // // } // Path: app/src/main/java/de/qspool/clementineremote/backend/listener/OnLibraryDownloadListener.java import de.qspool.clementineremote.backend.elements.DownloaderResult; /* This file is part of the Android Clementine Remote. * Copyright (C) 2013, Andreas Muttscheller <[email protected]> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package de.qspool.clementineremote.backend.listener; public interface OnLibraryDownloadListener { void OnProgressUpdate(long progress, int total); void OnOptimizeLibrary();
void OnLibraryDownloadFinished(DownloaderResult result);
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/soulevspy/obd/EstimatedRangeMessageFilter.java
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // }
import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter; import java.util.ArrayList;
package org.hexpresso.soulevspy.obd; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-13. * CAN Message ID 0x200 */ public class EstimatedRangeMessageFilter extends ObdMessageFilter { private int mEstimatedRangeKm = 0; public EstimatedRangeMessageFilter() { super("200"); } @Override
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // } // Path: app/src/main/java/org/hexpresso/soulevspy/obd/EstimatedRangeMessageFilter.java import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter; import java.util.ArrayList; package org.hexpresso.soulevspy.obd; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-13. * CAN Message ID 0x200 */ public class EstimatedRangeMessageFilter extends ObdMessageFilter { private int mEstimatedRangeKm = 0; public EstimatedRangeMessageFilter() { super("200"); } @Override
protected boolean doProcessMessage(ObdMessageData messageData) {
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/elm327/commands/filters/RegularExpressionResponseFilter.java
// Path: app/src/main/java/org/hexpresso/elm327/commands/Response.java // public class Response { // private String mRawResponse = null; // The raw ELM327 response as string // private List<String> mResponseLines = null; // Each array element represents a line // private List<ResponseFilter> mResponseFilters = null; // Response filters // // /** // * Constructor // */ // Response() { // } // // /** // * Sets the raw ELM327 response string // * @param rawResponse // */ // public void setRawResponse(String rawResponse) { // mRawResponse = rawResponse; // } // // /** // * Adds a response filter to be executed when processing the response // * @param responseFilter A ResponseFilter object // * @return Current response object // */ // public Response addResponseFilter(ResponseFilter responseFilter) { // if(mResponseFilters == null) { // mResponseFilters = new ArrayList<>(); // } // mResponseFilters.add(responseFilter); // return this; // } // // /** // * Processes the current Response object. // */ // public void process() { // if (mResponseLines == null) { // final String[] lines = mRawResponse.replaceAll("\\r", "").split("\\n"); // mResponseLines = new ArrayList<>(Arrays.asList(lines)); // } // // // Execute response filters (if any) // if(mResponseFilters != null) { // for(ResponseFilter filter: mResponseFilters) { // filter.onResponseReceived(this); // } // } // } // // public List<String> getLines() { // return mResponseLines; // } // // public String rawResponse() { // return mRawResponse; // } // // public int get(int byteIndex) { // return get(0, byteIndex); // } // // public int get(int lineIndex, int byteIndex) { // final String line = mResponseLines.get(lineIndex); // final int start = byteIndex * 2; // return HexToInteger(line.substring(start, start + 2)); // } // // public static int HexToInteger(String hex) { // return Integer.parseInt(hex, 16); // } // } // // Path: app/src/main/java/org/hexpresso/elm327/commands/ResponseFilter.java // public interface ResponseFilter { // /** // * // * @param response // */ // void onResponseReceived(Response response); // }
import org.hexpresso.elm327.commands.Response; import org.hexpresso.elm327.commands.ResponseFilter; import java.util.ArrayList; import java.util.List; import java.util.ListIterator; import java.util.regex.Matcher; import java.util.regex.Pattern;
package org.hexpresso.elm327.commands.filters; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-25. */ public class RegularExpressionResponseFilter implements ResponseFilter { private Pattern mPattern = null; public RegularExpressionResponseFilter(String regularExpression) { mPattern = Pattern.compile(regularExpression); } public RegularExpressionResponseFilter(Pattern pattern) { mPattern = pattern; } @Override
// Path: app/src/main/java/org/hexpresso/elm327/commands/Response.java // public class Response { // private String mRawResponse = null; // The raw ELM327 response as string // private List<String> mResponseLines = null; // Each array element represents a line // private List<ResponseFilter> mResponseFilters = null; // Response filters // // /** // * Constructor // */ // Response() { // } // // /** // * Sets the raw ELM327 response string // * @param rawResponse // */ // public void setRawResponse(String rawResponse) { // mRawResponse = rawResponse; // } // // /** // * Adds a response filter to be executed when processing the response // * @param responseFilter A ResponseFilter object // * @return Current response object // */ // public Response addResponseFilter(ResponseFilter responseFilter) { // if(mResponseFilters == null) { // mResponseFilters = new ArrayList<>(); // } // mResponseFilters.add(responseFilter); // return this; // } // // /** // * Processes the current Response object. // */ // public void process() { // if (mResponseLines == null) { // final String[] lines = mRawResponse.replaceAll("\\r", "").split("\\n"); // mResponseLines = new ArrayList<>(Arrays.asList(lines)); // } // // // Execute response filters (if any) // if(mResponseFilters != null) { // for(ResponseFilter filter: mResponseFilters) { // filter.onResponseReceived(this); // } // } // } // // public List<String> getLines() { // return mResponseLines; // } // // public String rawResponse() { // return mRawResponse; // } // // public int get(int byteIndex) { // return get(0, byteIndex); // } // // public int get(int lineIndex, int byteIndex) { // final String line = mResponseLines.get(lineIndex); // final int start = byteIndex * 2; // return HexToInteger(line.substring(start, start + 2)); // } // // public static int HexToInteger(String hex) { // return Integer.parseInt(hex, 16); // } // } // // Path: app/src/main/java/org/hexpresso/elm327/commands/ResponseFilter.java // public interface ResponseFilter { // /** // * // * @param response // */ // void onResponseReceived(Response response); // } // Path: app/src/main/java/org/hexpresso/elm327/commands/filters/RegularExpressionResponseFilter.java import org.hexpresso.elm327.commands.Response; import org.hexpresso.elm327.commands.ResponseFilter; import java.util.ArrayList; import java.util.List; import java.util.ListIterator; import java.util.regex.Matcher; import java.util.regex.Pattern; package org.hexpresso.elm327.commands.filters; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-25. */ public class RegularExpressionResponseFilter implements ResponseFilter { private Pattern mPattern = null; public RegularExpressionResponseFilter(String regularExpression) { mPattern = Pattern.compile(regularExpression); } public RegularExpressionResponseFilter(Pattern pattern) { mPattern = pattern; } @Override
public void onResponseReceived(Response response) {
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/elm327/io/Message.java
// Path: app/src/main/java/org/hexpresso/elm327/commands/Command.java // public interface Command { // // void execute(InputStream in, OutputStream out) throws IOException, InterruptedException; // // Response getResponse(); // }
import org.hexpresso.elm327.commands.Command; import java.util.concurrent.atomic.AtomicLong;
package org.hexpresso.elm327.io; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-28. */ public class Message { public enum State { READY, EXECUTING, FINISHED, // Errors ERROR_EXECUTION, ERROR_NOT_SUPPORTED, ERROR_QUEUE, ERROR_TIMEOUT } private static AtomicLong messageIdentifier = new AtomicLong(0L);
// Path: app/src/main/java/org/hexpresso/elm327/commands/Command.java // public interface Command { // // void execute(InputStream in, OutputStream out) throws IOException, InterruptedException; // // Response getResponse(); // } // Path: app/src/main/java/org/hexpresso/elm327/io/Message.java import org.hexpresso.elm327.commands.Command; import java.util.concurrent.atomic.AtomicLong; package org.hexpresso.elm327.io; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-28. */ public class Message { public enum State { READY, EXECUTING, FINISHED, // Errors ERROR_EXECUTION, ERROR_NOT_SUPPORTED, ERROR_QUEUE, ERROR_TIMEOUT } private static AtomicLong messageIdentifier = new AtomicLong(0L);
private final Command mCommand;
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/soulevspy/obd/Status018MessageFilter.java
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // }
import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter; import java.util.ArrayList;
package org.hexpresso.soulevspy.obd; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-13. */ public class Status018MessageFilter extends ObdMessageFilter { public Status018MessageFilter() { super("018"); } @Override
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // } // Path: app/src/main/java/org/hexpresso/soulevspy/obd/Status018MessageFilter.java import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter; import java.util.ArrayList; package org.hexpresso.soulevspy.obd; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-13. */ public class Status018MessageFilter extends ObdMessageFilter { public Status018MessageFilter() { super("018"); } @Override
protected boolean doProcessMessage(ObdMessageData messageData) {
pemessier/SoulEVSpy
app/src/androidTest/java/org/hexpresso/soulevspy/obd/OdometerMessageFilterTest.java
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // }
import android.test.AndroidTestCase; import junit.framework.Assert; import org.hexpresso.obd.ObdMessageData;
package org.hexpresso.soulevspy.obd; /** * Created by Tyrel on 10/17/2015. */ public class OdometerMessageFilterTest extends AndroidTestCase { public void testProcessesZero() { OdometerMessageFilter filter = new OdometerMessageFilter();
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // Path: app/src/androidTest/java/org/hexpresso/soulevspy/obd/OdometerMessageFilterTest.java import android.test.AndroidTestCase; import junit.framework.Assert; import org.hexpresso.obd.ObdMessageData; package org.hexpresso.soulevspy.obd; /** * Created by Tyrel on 10/17/2015. */ public class OdometerMessageFilterTest extends AndroidTestCase { public void testProcessesZero() { OdometerMessageFilter filter = new OdometerMessageFilter();
ObdMessageData messageData = new ObdMessageData("4F0 40 00 00 00 00 00 00 00");
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/elm327/commands/filters/RemoveSpacesResponseFilter.java
// Path: app/src/main/java/org/hexpresso/elm327/commands/Response.java // public class Response { // private String mRawResponse = null; // The raw ELM327 response as string // private List<String> mResponseLines = null; // Each array element represents a line // private List<ResponseFilter> mResponseFilters = null; // Response filters // // /** // * Constructor // */ // Response() { // } // // /** // * Sets the raw ELM327 response string // * @param rawResponse // */ // public void setRawResponse(String rawResponse) { // mRawResponse = rawResponse; // } // // /** // * Adds a response filter to be executed when processing the response // * @param responseFilter A ResponseFilter object // * @return Current response object // */ // public Response addResponseFilter(ResponseFilter responseFilter) { // if(mResponseFilters == null) { // mResponseFilters = new ArrayList<>(); // } // mResponseFilters.add(responseFilter); // return this; // } // // /** // * Processes the current Response object. // */ // public void process() { // if (mResponseLines == null) { // final String[] lines = mRawResponse.replaceAll("\\r", "").split("\\n"); // mResponseLines = new ArrayList<>(Arrays.asList(lines)); // } // // // Execute response filters (if any) // if(mResponseFilters != null) { // for(ResponseFilter filter: mResponseFilters) { // filter.onResponseReceived(this); // } // } // } // // public List<String> getLines() { // return mResponseLines; // } // // public String rawResponse() { // return mRawResponse; // } // // public int get(int byteIndex) { // return get(0, byteIndex); // } // // public int get(int lineIndex, int byteIndex) { // final String line = mResponseLines.get(lineIndex); // final int start = byteIndex * 2; // return HexToInteger(line.substring(start, start + 2)); // } // // public static int HexToInteger(String hex) { // return Integer.parseInt(hex, 16); // } // } // // Path: app/src/main/java/org/hexpresso/elm327/commands/ResponseFilter.java // public interface ResponseFilter { // /** // * // * @param response // */ // void onResponseReceived(Response response); // }
import org.hexpresso.elm327.commands.Response; import org.hexpresso.elm327.commands.ResponseFilter; import java.util.ListIterator;
package org.hexpresso.elm327.commands.filters; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-26. */ public class RemoveSpacesResponseFilter implements ResponseFilter { public RemoveSpacesResponseFilter() { } @Override
// Path: app/src/main/java/org/hexpresso/elm327/commands/Response.java // public class Response { // private String mRawResponse = null; // The raw ELM327 response as string // private List<String> mResponseLines = null; // Each array element represents a line // private List<ResponseFilter> mResponseFilters = null; // Response filters // // /** // * Constructor // */ // Response() { // } // // /** // * Sets the raw ELM327 response string // * @param rawResponse // */ // public void setRawResponse(String rawResponse) { // mRawResponse = rawResponse; // } // // /** // * Adds a response filter to be executed when processing the response // * @param responseFilter A ResponseFilter object // * @return Current response object // */ // public Response addResponseFilter(ResponseFilter responseFilter) { // if(mResponseFilters == null) { // mResponseFilters = new ArrayList<>(); // } // mResponseFilters.add(responseFilter); // return this; // } // // /** // * Processes the current Response object. // */ // public void process() { // if (mResponseLines == null) { // final String[] lines = mRawResponse.replaceAll("\\r", "").split("\\n"); // mResponseLines = new ArrayList<>(Arrays.asList(lines)); // } // // // Execute response filters (if any) // if(mResponseFilters != null) { // for(ResponseFilter filter: mResponseFilters) { // filter.onResponseReceived(this); // } // } // } // // public List<String> getLines() { // return mResponseLines; // } // // public String rawResponse() { // return mRawResponse; // } // // public int get(int byteIndex) { // return get(0, byteIndex); // } // // public int get(int lineIndex, int byteIndex) { // final String line = mResponseLines.get(lineIndex); // final int start = byteIndex * 2; // return HexToInteger(line.substring(start, start + 2)); // } // // public static int HexToInteger(String hex) { // return Integer.parseInt(hex, 16); // } // } // // Path: app/src/main/java/org/hexpresso/elm327/commands/ResponseFilter.java // public interface ResponseFilter { // /** // * // * @param response // */ // void onResponseReceived(Response response); // } // Path: app/src/main/java/org/hexpresso/elm327/commands/filters/RemoveSpacesResponseFilter.java import org.hexpresso.elm327.commands.Response; import org.hexpresso.elm327.commands.ResponseFilter; import java.util.ListIterator; package org.hexpresso.elm327.commands.filters; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-26. */ public class RemoveSpacesResponseFilter implements ResponseFilter { public RemoveSpacesResponseFilter() { } @Override
public void onResponseReceived(Response response) {
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/elm327/io/Protocol.java
// Path: app/src/main/java/org/hexpresso/elm327/commands/Command.java // public interface Command { // // void execute(InputStream in, OutputStream out) throws IOException, InterruptedException; // // Response getResponse(); // }
import org.hexpresso.elm327.commands.Command; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.LinkedBlockingQueue;
package org.hexpresso.elm327.io; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-27. */ public class Protocol { // private LinkedBlockingQueue<Message> mMessageInputQueue = new LinkedBlockingQueue<>(); private Thread mExecutionThread = null; // private LinkedBlockingQueue<Message> mMessageOutputQueue = new LinkedBlockingQueue<>(); private Thread mProcessingThread = null; private List<MessageReceivedListener> mMessageReceivedListeners = new ArrayList<>(); // Input/output streams private InputStream mInputStream = null; private OutputStream mOutputStream = null; public Protocol() { // Thread used to execute ELM327 commands mExecutionThread = new Thread(new Runnable() { @Override public void run() { executeMessages(); } }); // Thread used to process the received messages mProcessingThread = new Thread(new Runnable() { @Override public void run() { processReceivedMessages(); } }); } /** * Adds the specified Command to the message queue and execute it * @param command Command to execute * @return True if the command was successfully added, false otherwise */
// Path: app/src/main/java/org/hexpresso/elm327/commands/Command.java // public interface Command { // // void execute(InputStream in, OutputStream out) throws IOException, InterruptedException; // // Response getResponse(); // } // Path: app/src/main/java/org/hexpresso/elm327/io/Protocol.java import org.hexpresso.elm327.commands.Command; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.LinkedBlockingQueue; package org.hexpresso.elm327.io; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-27. */ public class Protocol { // private LinkedBlockingQueue<Message> mMessageInputQueue = new LinkedBlockingQueue<>(); private Thread mExecutionThread = null; // private LinkedBlockingQueue<Message> mMessageOutputQueue = new LinkedBlockingQueue<>(); private Thread mProcessingThread = null; private List<MessageReceivedListener> mMessageReceivedListeners = new ArrayList<>(); // Input/output streams private InputStream mInputStream = null; private OutputStream mOutputStream = null; public Protocol() { // Thread used to execute ELM327 commands mExecutionThread = new Thread(new Runnable() { @Override public void run() { executeMessages(); } }); // Thread used to process the received messages mProcessingThread = new Thread(new Runnable() { @Override public void run() { processReceivedMessages(); } }); } /** * Adds the specified Command to the message queue and execute it * @param command Command to execute * @return True if the command was successfully added, false otherwise */
public boolean addCommand(Command command) {
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/soulevspy/obd/TireRotationSpeedMessageFilter.java
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // }
import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter; import java.util.ArrayList;
package org.hexpresso.soulevspy.obd; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-13. */ public class TireRotationSpeedMessageFilter extends ObdMessageFilter { private double mLeftFrontSpeedKmH = 0.0; private double mRightFrontSpeedKmH = 0.0; private double mLeftBackSpeedKmH = 0.0; private double mRightBackSpeedKmH = 0.0; public TireRotationSpeedMessageFilter() { super("4B0"); } @Override
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // } // Path: app/src/main/java/org/hexpresso/soulevspy/obd/TireRotationSpeedMessageFilter.java import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter; import java.util.ArrayList; package org.hexpresso.soulevspy.obd; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-13. */ public class TireRotationSpeedMessageFilter extends ObdMessageFilter { private double mLeftFrontSpeedKmH = 0.0; private double mRightFrontSpeedKmH = 0.0; private double mLeftBackSpeedKmH = 0.0; private double mRightBackSpeedKmH = 0.0; public TireRotationSpeedMessageFilter() { super("4B0"); } @Override
protected boolean doProcessMessage(ObdMessageData messageData) {
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/elm327/commands/AbstractCommand.java
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/BusInitException.java // public class BusInitException extends ResponseException { // // public BusInitException() { // super("BUS INIT... ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/MisunderstoodCommandException.java // public class MisunderstoodCommandException extends ResponseException { // // public MisunderstoodCommandException() { // super("?"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/NoDataException.java // public class NoDataException extends ResponseException { // // public NoDataException() { // super("NO DATA"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/ResponseException.java // public class ResponseException extends RuntimeException { // // private String message; // // private String response; // // private String command; // // private boolean matchRegex; // // /** // * @param message a {@link java.lang.String} object. // */ // protected ResponseException(String message) { // this.message = message; // } // // protected ResponseException(String message, boolean matchRegex) { // this.message = message; // this.matchRegex = matchRegex; // } // // private static String clean(String s) { // return s == null ? "" : s.replaceAll("\\s", "").toUpperCase(); // } // // /** // * @param response a {@link java.lang.String} object. // * @return a boolean. // */ // public boolean isError(String response) { // this.response = response; // if (matchRegex) { // return clean(response).matches(clean(message)); // } else { // return clean(response).contains(clean(message)); // } // } // // /** // * @param command a {@link java.lang.String} object. // */ // public void setCommand(String command) { // this.command = command; // } // // @Override // public String getMessage() { // return "Error running " + command + ", response: " + response; // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/StoppedException.java // public class StoppedException extends ResponseException { // // public StoppedException() { // super("STOPPED"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnableToConnectException.java // public class UnableToConnectException extends ResponseException { // // public UnableToConnectException() { // super("UNABLE TO CONNECT"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnknownErrorException.java // public class UnknownErrorException extends ResponseException { // // public UnknownErrorException() { // super("ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnsupportedCommandException.java // public class UnsupportedCommandException extends ResponseException { // // public UnsupportedCommandException() { // super("7F 0[0-9] 12", true); // } // // }
import org.hexpresso.elm327.exceptions.BusInitException; import org.hexpresso.elm327.exceptions.MisunderstoodCommandException; import org.hexpresso.elm327.exceptions.NoDataException; import org.hexpresso.elm327.exceptions.ResponseException; import org.hexpresso.elm327.exceptions.StoppedException; import org.hexpresso.elm327.exceptions.UnableToConnectException; import org.hexpresso.elm327.exceptions.UnknownErrorException; import org.hexpresso.elm327.exceptions.UnsupportedCommandException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream;
package org.hexpresso.elm327.commands; /** * The AbstractCommand class represents an ELM327 command. * <p/> * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-24. */ public abstract class AbstractCommand implements Command { protected String mCommand = null; // ELM327 command protected long mResponseTimeDelay = 200; // Time delay before receiving the response, in milliseconds protected Response mResponse = new Response(); // Response object private long mRunStartTimestamp; // Timestamp before sending the command private long mRunEndTimestamp; // Timestamp after receiving the command response private boolean mWithAutoProcessResponse = false; // /** * Error classes to be tested in order */ private final static Class[] ERROR_CLASSES = {
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/BusInitException.java // public class BusInitException extends ResponseException { // // public BusInitException() { // super("BUS INIT... ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/MisunderstoodCommandException.java // public class MisunderstoodCommandException extends ResponseException { // // public MisunderstoodCommandException() { // super("?"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/NoDataException.java // public class NoDataException extends ResponseException { // // public NoDataException() { // super("NO DATA"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/ResponseException.java // public class ResponseException extends RuntimeException { // // private String message; // // private String response; // // private String command; // // private boolean matchRegex; // // /** // * @param message a {@link java.lang.String} object. // */ // protected ResponseException(String message) { // this.message = message; // } // // protected ResponseException(String message, boolean matchRegex) { // this.message = message; // this.matchRegex = matchRegex; // } // // private static String clean(String s) { // return s == null ? "" : s.replaceAll("\\s", "").toUpperCase(); // } // // /** // * @param response a {@link java.lang.String} object. // * @return a boolean. // */ // public boolean isError(String response) { // this.response = response; // if (matchRegex) { // return clean(response).matches(clean(message)); // } else { // return clean(response).contains(clean(message)); // } // } // // /** // * @param command a {@link java.lang.String} object. // */ // public void setCommand(String command) { // this.command = command; // } // // @Override // public String getMessage() { // return "Error running " + command + ", response: " + response; // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/StoppedException.java // public class StoppedException extends ResponseException { // // public StoppedException() { // super("STOPPED"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnableToConnectException.java // public class UnableToConnectException extends ResponseException { // // public UnableToConnectException() { // super("UNABLE TO CONNECT"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnknownErrorException.java // public class UnknownErrorException extends ResponseException { // // public UnknownErrorException() { // super("ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnsupportedCommandException.java // public class UnsupportedCommandException extends ResponseException { // // public UnsupportedCommandException() { // super("7F 0[0-9] 12", true); // } // // } // Path: app/src/main/java/org/hexpresso/elm327/commands/AbstractCommand.java import org.hexpresso.elm327.exceptions.BusInitException; import org.hexpresso.elm327.exceptions.MisunderstoodCommandException; import org.hexpresso.elm327.exceptions.NoDataException; import org.hexpresso.elm327.exceptions.ResponseException; import org.hexpresso.elm327.exceptions.StoppedException; import org.hexpresso.elm327.exceptions.UnableToConnectException; import org.hexpresso.elm327.exceptions.UnknownErrorException; import org.hexpresso.elm327.exceptions.UnsupportedCommandException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; package org.hexpresso.elm327.commands; /** * The AbstractCommand class represents an ELM327 command. * <p/> * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-24. */ public abstract class AbstractCommand implements Command { protected String mCommand = null; // ELM327 command protected long mResponseTimeDelay = 200; // Time delay before receiving the response, in milliseconds protected Response mResponse = new Response(); // Response object private long mRunStartTimestamp; // Timestamp before sending the command private long mRunEndTimestamp; // Timestamp after receiving the command response private boolean mWithAutoProcessResponse = false; // /** * Error classes to be tested in order */ private final static Class[] ERROR_CLASSES = {
UnableToConnectException.class,
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/elm327/commands/AbstractCommand.java
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/BusInitException.java // public class BusInitException extends ResponseException { // // public BusInitException() { // super("BUS INIT... ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/MisunderstoodCommandException.java // public class MisunderstoodCommandException extends ResponseException { // // public MisunderstoodCommandException() { // super("?"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/NoDataException.java // public class NoDataException extends ResponseException { // // public NoDataException() { // super("NO DATA"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/ResponseException.java // public class ResponseException extends RuntimeException { // // private String message; // // private String response; // // private String command; // // private boolean matchRegex; // // /** // * @param message a {@link java.lang.String} object. // */ // protected ResponseException(String message) { // this.message = message; // } // // protected ResponseException(String message, boolean matchRegex) { // this.message = message; // this.matchRegex = matchRegex; // } // // private static String clean(String s) { // return s == null ? "" : s.replaceAll("\\s", "").toUpperCase(); // } // // /** // * @param response a {@link java.lang.String} object. // * @return a boolean. // */ // public boolean isError(String response) { // this.response = response; // if (matchRegex) { // return clean(response).matches(clean(message)); // } else { // return clean(response).contains(clean(message)); // } // } // // /** // * @param command a {@link java.lang.String} object. // */ // public void setCommand(String command) { // this.command = command; // } // // @Override // public String getMessage() { // return "Error running " + command + ", response: " + response; // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/StoppedException.java // public class StoppedException extends ResponseException { // // public StoppedException() { // super("STOPPED"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnableToConnectException.java // public class UnableToConnectException extends ResponseException { // // public UnableToConnectException() { // super("UNABLE TO CONNECT"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnknownErrorException.java // public class UnknownErrorException extends ResponseException { // // public UnknownErrorException() { // super("ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnsupportedCommandException.java // public class UnsupportedCommandException extends ResponseException { // // public UnsupportedCommandException() { // super("7F 0[0-9] 12", true); // } // // }
import org.hexpresso.elm327.exceptions.BusInitException; import org.hexpresso.elm327.exceptions.MisunderstoodCommandException; import org.hexpresso.elm327.exceptions.NoDataException; import org.hexpresso.elm327.exceptions.ResponseException; import org.hexpresso.elm327.exceptions.StoppedException; import org.hexpresso.elm327.exceptions.UnableToConnectException; import org.hexpresso.elm327.exceptions.UnknownErrorException; import org.hexpresso.elm327.exceptions.UnsupportedCommandException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream;
package org.hexpresso.elm327.commands; /** * The AbstractCommand class represents an ELM327 command. * <p/> * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-24. */ public abstract class AbstractCommand implements Command { protected String mCommand = null; // ELM327 command protected long mResponseTimeDelay = 200; // Time delay before receiving the response, in milliseconds protected Response mResponse = new Response(); // Response object private long mRunStartTimestamp; // Timestamp before sending the command private long mRunEndTimestamp; // Timestamp after receiving the command response private boolean mWithAutoProcessResponse = false; // /** * Error classes to be tested in order */ private final static Class[] ERROR_CLASSES = { UnableToConnectException.class,
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/BusInitException.java // public class BusInitException extends ResponseException { // // public BusInitException() { // super("BUS INIT... ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/MisunderstoodCommandException.java // public class MisunderstoodCommandException extends ResponseException { // // public MisunderstoodCommandException() { // super("?"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/NoDataException.java // public class NoDataException extends ResponseException { // // public NoDataException() { // super("NO DATA"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/ResponseException.java // public class ResponseException extends RuntimeException { // // private String message; // // private String response; // // private String command; // // private boolean matchRegex; // // /** // * @param message a {@link java.lang.String} object. // */ // protected ResponseException(String message) { // this.message = message; // } // // protected ResponseException(String message, boolean matchRegex) { // this.message = message; // this.matchRegex = matchRegex; // } // // private static String clean(String s) { // return s == null ? "" : s.replaceAll("\\s", "").toUpperCase(); // } // // /** // * @param response a {@link java.lang.String} object. // * @return a boolean. // */ // public boolean isError(String response) { // this.response = response; // if (matchRegex) { // return clean(response).matches(clean(message)); // } else { // return clean(response).contains(clean(message)); // } // } // // /** // * @param command a {@link java.lang.String} object. // */ // public void setCommand(String command) { // this.command = command; // } // // @Override // public String getMessage() { // return "Error running " + command + ", response: " + response; // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/StoppedException.java // public class StoppedException extends ResponseException { // // public StoppedException() { // super("STOPPED"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnableToConnectException.java // public class UnableToConnectException extends ResponseException { // // public UnableToConnectException() { // super("UNABLE TO CONNECT"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnknownErrorException.java // public class UnknownErrorException extends ResponseException { // // public UnknownErrorException() { // super("ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnsupportedCommandException.java // public class UnsupportedCommandException extends ResponseException { // // public UnsupportedCommandException() { // super("7F 0[0-9] 12", true); // } // // } // Path: app/src/main/java/org/hexpresso/elm327/commands/AbstractCommand.java import org.hexpresso.elm327.exceptions.BusInitException; import org.hexpresso.elm327.exceptions.MisunderstoodCommandException; import org.hexpresso.elm327.exceptions.NoDataException; import org.hexpresso.elm327.exceptions.ResponseException; import org.hexpresso.elm327.exceptions.StoppedException; import org.hexpresso.elm327.exceptions.UnableToConnectException; import org.hexpresso.elm327.exceptions.UnknownErrorException; import org.hexpresso.elm327.exceptions.UnsupportedCommandException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; package org.hexpresso.elm327.commands; /** * The AbstractCommand class represents an ELM327 command. * <p/> * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-24. */ public abstract class AbstractCommand implements Command { protected String mCommand = null; // ELM327 command protected long mResponseTimeDelay = 200; // Time delay before receiving the response, in milliseconds protected Response mResponse = new Response(); // Response object private long mRunStartTimestamp; // Timestamp before sending the command private long mRunEndTimestamp; // Timestamp after receiving the command response private boolean mWithAutoProcessResponse = false; // /** * Error classes to be tested in order */ private final static Class[] ERROR_CLASSES = { UnableToConnectException.class,
BusInitException.class,
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/elm327/commands/AbstractCommand.java
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/BusInitException.java // public class BusInitException extends ResponseException { // // public BusInitException() { // super("BUS INIT... ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/MisunderstoodCommandException.java // public class MisunderstoodCommandException extends ResponseException { // // public MisunderstoodCommandException() { // super("?"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/NoDataException.java // public class NoDataException extends ResponseException { // // public NoDataException() { // super("NO DATA"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/ResponseException.java // public class ResponseException extends RuntimeException { // // private String message; // // private String response; // // private String command; // // private boolean matchRegex; // // /** // * @param message a {@link java.lang.String} object. // */ // protected ResponseException(String message) { // this.message = message; // } // // protected ResponseException(String message, boolean matchRegex) { // this.message = message; // this.matchRegex = matchRegex; // } // // private static String clean(String s) { // return s == null ? "" : s.replaceAll("\\s", "").toUpperCase(); // } // // /** // * @param response a {@link java.lang.String} object. // * @return a boolean. // */ // public boolean isError(String response) { // this.response = response; // if (matchRegex) { // return clean(response).matches(clean(message)); // } else { // return clean(response).contains(clean(message)); // } // } // // /** // * @param command a {@link java.lang.String} object. // */ // public void setCommand(String command) { // this.command = command; // } // // @Override // public String getMessage() { // return "Error running " + command + ", response: " + response; // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/StoppedException.java // public class StoppedException extends ResponseException { // // public StoppedException() { // super("STOPPED"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnableToConnectException.java // public class UnableToConnectException extends ResponseException { // // public UnableToConnectException() { // super("UNABLE TO CONNECT"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnknownErrorException.java // public class UnknownErrorException extends ResponseException { // // public UnknownErrorException() { // super("ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnsupportedCommandException.java // public class UnsupportedCommandException extends ResponseException { // // public UnsupportedCommandException() { // super("7F 0[0-9] 12", true); // } // // }
import org.hexpresso.elm327.exceptions.BusInitException; import org.hexpresso.elm327.exceptions.MisunderstoodCommandException; import org.hexpresso.elm327.exceptions.NoDataException; import org.hexpresso.elm327.exceptions.ResponseException; import org.hexpresso.elm327.exceptions.StoppedException; import org.hexpresso.elm327.exceptions.UnableToConnectException; import org.hexpresso.elm327.exceptions.UnknownErrorException; import org.hexpresso.elm327.exceptions.UnsupportedCommandException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream;
package org.hexpresso.elm327.commands; /** * The AbstractCommand class represents an ELM327 command. * <p/> * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-24. */ public abstract class AbstractCommand implements Command { protected String mCommand = null; // ELM327 command protected long mResponseTimeDelay = 200; // Time delay before receiving the response, in milliseconds protected Response mResponse = new Response(); // Response object private long mRunStartTimestamp; // Timestamp before sending the command private long mRunEndTimestamp; // Timestamp after receiving the command response private boolean mWithAutoProcessResponse = false; // /** * Error classes to be tested in order */ private final static Class[] ERROR_CLASSES = { UnableToConnectException.class, BusInitException.class,
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/BusInitException.java // public class BusInitException extends ResponseException { // // public BusInitException() { // super("BUS INIT... ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/MisunderstoodCommandException.java // public class MisunderstoodCommandException extends ResponseException { // // public MisunderstoodCommandException() { // super("?"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/NoDataException.java // public class NoDataException extends ResponseException { // // public NoDataException() { // super("NO DATA"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/ResponseException.java // public class ResponseException extends RuntimeException { // // private String message; // // private String response; // // private String command; // // private boolean matchRegex; // // /** // * @param message a {@link java.lang.String} object. // */ // protected ResponseException(String message) { // this.message = message; // } // // protected ResponseException(String message, boolean matchRegex) { // this.message = message; // this.matchRegex = matchRegex; // } // // private static String clean(String s) { // return s == null ? "" : s.replaceAll("\\s", "").toUpperCase(); // } // // /** // * @param response a {@link java.lang.String} object. // * @return a boolean. // */ // public boolean isError(String response) { // this.response = response; // if (matchRegex) { // return clean(response).matches(clean(message)); // } else { // return clean(response).contains(clean(message)); // } // } // // /** // * @param command a {@link java.lang.String} object. // */ // public void setCommand(String command) { // this.command = command; // } // // @Override // public String getMessage() { // return "Error running " + command + ", response: " + response; // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/StoppedException.java // public class StoppedException extends ResponseException { // // public StoppedException() { // super("STOPPED"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnableToConnectException.java // public class UnableToConnectException extends ResponseException { // // public UnableToConnectException() { // super("UNABLE TO CONNECT"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnknownErrorException.java // public class UnknownErrorException extends ResponseException { // // public UnknownErrorException() { // super("ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnsupportedCommandException.java // public class UnsupportedCommandException extends ResponseException { // // public UnsupportedCommandException() { // super("7F 0[0-9] 12", true); // } // // } // Path: app/src/main/java/org/hexpresso/elm327/commands/AbstractCommand.java import org.hexpresso.elm327.exceptions.BusInitException; import org.hexpresso.elm327.exceptions.MisunderstoodCommandException; import org.hexpresso.elm327.exceptions.NoDataException; import org.hexpresso.elm327.exceptions.ResponseException; import org.hexpresso.elm327.exceptions.StoppedException; import org.hexpresso.elm327.exceptions.UnableToConnectException; import org.hexpresso.elm327.exceptions.UnknownErrorException; import org.hexpresso.elm327.exceptions.UnsupportedCommandException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; package org.hexpresso.elm327.commands; /** * The AbstractCommand class represents an ELM327 command. * <p/> * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-24. */ public abstract class AbstractCommand implements Command { protected String mCommand = null; // ELM327 command protected long mResponseTimeDelay = 200; // Time delay before receiving the response, in milliseconds protected Response mResponse = new Response(); // Response object private long mRunStartTimestamp; // Timestamp before sending the command private long mRunEndTimestamp; // Timestamp after receiving the command response private boolean mWithAutoProcessResponse = false; // /** * Error classes to be tested in order */ private final static Class[] ERROR_CLASSES = { UnableToConnectException.class, BusInitException.class,
MisunderstoodCommandException.class,
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/elm327/commands/AbstractCommand.java
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/BusInitException.java // public class BusInitException extends ResponseException { // // public BusInitException() { // super("BUS INIT... ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/MisunderstoodCommandException.java // public class MisunderstoodCommandException extends ResponseException { // // public MisunderstoodCommandException() { // super("?"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/NoDataException.java // public class NoDataException extends ResponseException { // // public NoDataException() { // super("NO DATA"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/ResponseException.java // public class ResponseException extends RuntimeException { // // private String message; // // private String response; // // private String command; // // private boolean matchRegex; // // /** // * @param message a {@link java.lang.String} object. // */ // protected ResponseException(String message) { // this.message = message; // } // // protected ResponseException(String message, boolean matchRegex) { // this.message = message; // this.matchRegex = matchRegex; // } // // private static String clean(String s) { // return s == null ? "" : s.replaceAll("\\s", "").toUpperCase(); // } // // /** // * @param response a {@link java.lang.String} object. // * @return a boolean. // */ // public boolean isError(String response) { // this.response = response; // if (matchRegex) { // return clean(response).matches(clean(message)); // } else { // return clean(response).contains(clean(message)); // } // } // // /** // * @param command a {@link java.lang.String} object. // */ // public void setCommand(String command) { // this.command = command; // } // // @Override // public String getMessage() { // return "Error running " + command + ", response: " + response; // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/StoppedException.java // public class StoppedException extends ResponseException { // // public StoppedException() { // super("STOPPED"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnableToConnectException.java // public class UnableToConnectException extends ResponseException { // // public UnableToConnectException() { // super("UNABLE TO CONNECT"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnknownErrorException.java // public class UnknownErrorException extends ResponseException { // // public UnknownErrorException() { // super("ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnsupportedCommandException.java // public class UnsupportedCommandException extends ResponseException { // // public UnsupportedCommandException() { // super("7F 0[0-9] 12", true); // } // // }
import org.hexpresso.elm327.exceptions.BusInitException; import org.hexpresso.elm327.exceptions.MisunderstoodCommandException; import org.hexpresso.elm327.exceptions.NoDataException; import org.hexpresso.elm327.exceptions.ResponseException; import org.hexpresso.elm327.exceptions.StoppedException; import org.hexpresso.elm327.exceptions.UnableToConnectException; import org.hexpresso.elm327.exceptions.UnknownErrorException; import org.hexpresso.elm327.exceptions.UnsupportedCommandException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream;
package org.hexpresso.elm327.commands; /** * The AbstractCommand class represents an ELM327 command. * <p/> * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-24. */ public abstract class AbstractCommand implements Command { protected String mCommand = null; // ELM327 command protected long mResponseTimeDelay = 200; // Time delay before receiving the response, in milliseconds protected Response mResponse = new Response(); // Response object private long mRunStartTimestamp; // Timestamp before sending the command private long mRunEndTimestamp; // Timestamp after receiving the command response private boolean mWithAutoProcessResponse = false; // /** * Error classes to be tested in order */ private final static Class[] ERROR_CLASSES = { UnableToConnectException.class, BusInitException.class, MisunderstoodCommandException.class,
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/BusInitException.java // public class BusInitException extends ResponseException { // // public BusInitException() { // super("BUS INIT... ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/MisunderstoodCommandException.java // public class MisunderstoodCommandException extends ResponseException { // // public MisunderstoodCommandException() { // super("?"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/NoDataException.java // public class NoDataException extends ResponseException { // // public NoDataException() { // super("NO DATA"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/ResponseException.java // public class ResponseException extends RuntimeException { // // private String message; // // private String response; // // private String command; // // private boolean matchRegex; // // /** // * @param message a {@link java.lang.String} object. // */ // protected ResponseException(String message) { // this.message = message; // } // // protected ResponseException(String message, boolean matchRegex) { // this.message = message; // this.matchRegex = matchRegex; // } // // private static String clean(String s) { // return s == null ? "" : s.replaceAll("\\s", "").toUpperCase(); // } // // /** // * @param response a {@link java.lang.String} object. // * @return a boolean. // */ // public boolean isError(String response) { // this.response = response; // if (matchRegex) { // return clean(response).matches(clean(message)); // } else { // return clean(response).contains(clean(message)); // } // } // // /** // * @param command a {@link java.lang.String} object. // */ // public void setCommand(String command) { // this.command = command; // } // // @Override // public String getMessage() { // return "Error running " + command + ", response: " + response; // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/StoppedException.java // public class StoppedException extends ResponseException { // // public StoppedException() { // super("STOPPED"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnableToConnectException.java // public class UnableToConnectException extends ResponseException { // // public UnableToConnectException() { // super("UNABLE TO CONNECT"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnknownErrorException.java // public class UnknownErrorException extends ResponseException { // // public UnknownErrorException() { // super("ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnsupportedCommandException.java // public class UnsupportedCommandException extends ResponseException { // // public UnsupportedCommandException() { // super("7F 0[0-9] 12", true); // } // // } // Path: app/src/main/java/org/hexpresso/elm327/commands/AbstractCommand.java import org.hexpresso.elm327.exceptions.BusInitException; import org.hexpresso.elm327.exceptions.MisunderstoodCommandException; import org.hexpresso.elm327.exceptions.NoDataException; import org.hexpresso.elm327.exceptions.ResponseException; import org.hexpresso.elm327.exceptions.StoppedException; import org.hexpresso.elm327.exceptions.UnableToConnectException; import org.hexpresso.elm327.exceptions.UnknownErrorException; import org.hexpresso.elm327.exceptions.UnsupportedCommandException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; package org.hexpresso.elm327.commands; /** * The AbstractCommand class represents an ELM327 command. * <p/> * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-24. */ public abstract class AbstractCommand implements Command { protected String mCommand = null; // ELM327 command protected long mResponseTimeDelay = 200; // Time delay before receiving the response, in milliseconds protected Response mResponse = new Response(); // Response object private long mRunStartTimestamp; // Timestamp before sending the command private long mRunEndTimestamp; // Timestamp after receiving the command response private boolean mWithAutoProcessResponse = false; // /** * Error classes to be tested in order */ private final static Class[] ERROR_CLASSES = { UnableToConnectException.class, BusInitException.class, MisunderstoodCommandException.class,
NoDataException.class,
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/elm327/commands/AbstractCommand.java
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/BusInitException.java // public class BusInitException extends ResponseException { // // public BusInitException() { // super("BUS INIT... ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/MisunderstoodCommandException.java // public class MisunderstoodCommandException extends ResponseException { // // public MisunderstoodCommandException() { // super("?"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/NoDataException.java // public class NoDataException extends ResponseException { // // public NoDataException() { // super("NO DATA"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/ResponseException.java // public class ResponseException extends RuntimeException { // // private String message; // // private String response; // // private String command; // // private boolean matchRegex; // // /** // * @param message a {@link java.lang.String} object. // */ // protected ResponseException(String message) { // this.message = message; // } // // protected ResponseException(String message, boolean matchRegex) { // this.message = message; // this.matchRegex = matchRegex; // } // // private static String clean(String s) { // return s == null ? "" : s.replaceAll("\\s", "").toUpperCase(); // } // // /** // * @param response a {@link java.lang.String} object. // * @return a boolean. // */ // public boolean isError(String response) { // this.response = response; // if (matchRegex) { // return clean(response).matches(clean(message)); // } else { // return clean(response).contains(clean(message)); // } // } // // /** // * @param command a {@link java.lang.String} object. // */ // public void setCommand(String command) { // this.command = command; // } // // @Override // public String getMessage() { // return "Error running " + command + ", response: " + response; // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/StoppedException.java // public class StoppedException extends ResponseException { // // public StoppedException() { // super("STOPPED"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnableToConnectException.java // public class UnableToConnectException extends ResponseException { // // public UnableToConnectException() { // super("UNABLE TO CONNECT"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnknownErrorException.java // public class UnknownErrorException extends ResponseException { // // public UnknownErrorException() { // super("ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnsupportedCommandException.java // public class UnsupportedCommandException extends ResponseException { // // public UnsupportedCommandException() { // super("7F 0[0-9] 12", true); // } // // }
import org.hexpresso.elm327.exceptions.BusInitException; import org.hexpresso.elm327.exceptions.MisunderstoodCommandException; import org.hexpresso.elm327.exceptions.NoDataException; import org.hexpresso.elm327.exceptions.ResponseException; import org.hexpresso.elm327.exceptions.StoppedException; import org.hexpresso.elm327.exceptions.UnableToConnectException; import org.hexpresso.elm327.exceptions.UnknownErrorException; import org.hexpresso.elm327.exceptions.UnsupportedCommandException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream;
package org.hexpresso.elm327.commands; /** * The AbstractCommand class represents an ELM327 command. * <p/> * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-24. */ public abstract class AbstractCommand implements Command { protected String mCommand = null; // ELM327 command protected long mResponseTimeDelay = 200; // Time delay before receiving the response, in milliseconds protected Response mResponse = new Response(); // Response object private long mRunStartTimestamp; // Timestamp before sending the command private long mRunEndTimestamp; // Timestamp after receiving the command response private boolean mWithAutoProcessResponse = false; // /** * Error classes to be tested in order */ private final static Class[] ERROR_CLASSES = { UnableToConnectException.class, BusInitException.class, MisunderstoodCommandException.class, NoDataException.class,
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/BusInitException.java // public class BusInitException extends ResponseException { // // public BusInitException() { // super("BUS INIT... ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/MisunderstoodCommandException.java // public class MisunderstoodCommandException extends ResponseException { // // public MisunderstoodCommandException() { // super("?"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/NoDataException.java // public class NoDataException extends ResponseException { // // public NoDataException() { // super("NO DATA"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/ResponseException.java // public class ResponseException extends RuntimeException { // // private String message; // // private String response; // // private String command; // // private boolean matchRegex; // // /** // * @param message a {@link java.lang.String} object. // */ // protected ResponseException(String message) { // this.message = message; // } // // protected ResponseException(String message, boolean matchRegex) { // this.message = message; // this.matchRegex = matchRegex; // } // // private static String clean(String s) { // return s == null ? "" : s.replaceAll("\\s", "").toUpperCase(); // } // // /** // * @param response a {@link java.lang.String} object. // * @return a boolean. // */ // public boolean isError(String response) { // this.response = response; // if (matchRegex) { // return clean(response).matches(clean(message)); // } else { // return clean(response).contains(clean(message)); // } // } // // /** // * @param command a {@link java.lang.String} object. // */ // public void setCommand(String command) { // this.command = command; // } // // @Override // public String getMessage() { // return "Error running " + command + ", response: " + response; // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/StoppedException.java // public class StoppedException extends ResponseException { // // public StoppedException() { // super("STOPPED"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnableToConnectException.java // public class UnableToConnectException extends ResponseException { // // public UnableToConnectException() { // super("UNABLE TO CONNECT"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnknownErrorException.java // public class UnknownErrorException extends ResponseException { // // public UnknownErrorException() { // super("ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnsupportedCommandException.java // public class UnsupportedCommandException extends ResponseException { // // public UnsupportedCommandException() { // super("7F 0[0-9] 12", true); // } // // } // Path: app/src/main/java/org/hexpresso/elm327/commands/AbstractCommand.java import org.hexpresso.elm327.exceptions.BusInitException; import org.hexpresso.elm327.exceptions.MisunderstoodCommandException; import org.hexpresso.elm327.exceptions.NoDataException; import org.hexpresso.elm327.exceptions.ResponseException; import org.hexpresso.elm327.exceptions.StoppedException; import org.hexpresso.elm327.exceptions.UnableToConnectException; import org.hexpresso.elm327.exceptions.UnknownErrorException; import org.hexpresso.elm327.exceptions.UnsupportedCommandException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; package org.hexpresso.elm327.commands; /** * The AbstractCommand class represents an ELM327 command. * <p/> * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-24. */ public abstract class AbstractCommand implements Command { protected String mCommand = null; // ELM327 command protected long mResponseTimeDelay = 200; // Time delay before receiving the response, in milliseconds protected Response mResponse = new Response(); // Response object private long mRunStartTimestamp; // Timestamp before sending the command private long mRunEndTimestamp; // Timestamp after receiving the command response private boolean mWithAutoProcessResponse = false; // /** * Error classes to be tested in order */ private final static Class[] ERROR_CLASSES = { UnableToConnectException.class, BusInitException.class, MisunderstoodCommandException.class, NoDataException.class,
StoppedException.class,
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/elm327/commands/AbstractCommand.java
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/BusInitException.java // public class BusInitException extends ResponseException { // // public BusInitException() { // super("BUS INIT... ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/MisunderstoodCommandException.java // public class MisunderstoodCommandException extends ResponseException { // // public MisunderstoodCommandException() { // super("?"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/NoDataException.java // public class NoDataException extends ResponseException { // // public NoDataException() { // super("NO DATA"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/ResponseException.java // public class ResponseException extends RuntimeException { // // private String message; // // private String response; // // private String command; // // private boolean matchRegex; // // /** // * @param message a {@link java.lang.String} object. // */ // protected ResponseException(String message) { // this.message = message; // } // // protected ResponseException(String message, boolean matchRegex) { // this.message = message; // this.matchRegex = matchRegex; // } // // private static String clean(String s) { // return s == null ? "" : s.replaceAll("\\s", "").toUpperCase(); // } // // /** // * @param response a {@link java.lang.String} object. // * @return a boolean. // */ // public boolean isError(String response) { // this.response = response; // if (matchRegex) { // return clean(response).matches(clean(message)); // } else { // return clean(response).contains(clean(message)); // } // } // // /** // * @param command a {@link java.lang.String} object. // */ // public void setCommand(String command) { // this.command = command; // } // // @Override // public String getMessage() { // return "Error running " + command + ", response: " + response; // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/StoppedException.java // public class StoppedException extends ResponseException { // // public StoppedException() { // super("STOPPED"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnableToConnectException.java // public class UnableToConnectException extends ResponseException { // // public UnableToConnectException() { // super("UNABLE TO CONNECT"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnknownErrorException.java // public class UnknownErrorException extends ResponseException { // // public UnknownErrorException() { // super("ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnsupportedCommandException.java // public class UnsupportedCommandException extends ResponseException { // // public UnsupportedCommandException() { // super("7F 0[0-9] 12", true); // } // // }
import org.hexpresso.elm327.exceptions.BusInitException; import org.hexpresso.elm327.exceptions.MisunderstoodCommandException; import org.hexpresso.elm327.exceptions.NoDataException; import org.hexpresso.elm327.exceptions.ResponseException; import org.hexpresso.elm327.exceptions.StoppedException; import org.hexpresso.elm327.exceptions.UnableToConnectException; import org.hexpresso.elm327.exceptions.UnknownErrorException; import org.hexpresso.elm327.exceptions.UnsupportedCommandException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream;
package org.hexpresso.elm327.commands; /** * The AbstractCommand class represents an ELM327 command. * <p/> * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-24. */ public abstract class AbstractCommand implements Command { protected String mCommand = null; // ELM327 command protected long mResponseTimeDelay = 200; // Time delay before receiving the response, in milliseconds protected Response mResponse = new Response(); // Response object private long mRunStartTimestamp; // Timestamp before sending the command private long mRunEndTimestamp; // Timestamp after receiving the command response private boolean mWithAutoProcessResponse = false; // /** * Error classes to be tested in order */ private final static Class[] ERROR_CLASSES = { UnableToConnectException.class, BusInitException.class, MisunderstoodCommandException.class, NoDataException.class, StoppedException.class,
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/BusInitException.java // public class BusInitException extends ResponseException { // // public BusInitException() { // super("BUS INIT... ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/MisunderstoodCommandException.java // public class MisunderstoodCommandException extends ResponseException { // // public MisunderstoodCommandException() { // super("?"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/NoDataException.java // public class NoDataException extends ResponseException { // // public NoDataException() { // super("NO DATA"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/ResponseException.java // public class ResponseException extends RuntimeException { // // private String message; // // private String response; // // private String command; // // private boolean matchRegex; // // /** // * @param message a {@link java.lang.String} object. // */ // protected ResponseException(String message) { // this.message = message; // } // // protected ResponseException(String message, boolean matchRegex) { // this.message = message; // this.matchRegex = matchRegex; // } // // private static String clean(String s) { // return s == null ? "" : s.replaceAll("\\s", "").toUpperCase(); // } // // /** // * @param response a {@link java.lang.String} object. // * @return a boolean. // */ // public boolean isError(String response) { // this.response = response; // if (matchRegex) { // return clean(response).matches(clean(message)); // } else { // return clean(response).contains(clean(message)); // } // } // // /** // * @param command a {@link java.lang.String} object. // */ // public void setCommand(String command) { // this.command = command; // } // // @Override // public String getMessage() { // return "Error running " + command + ", response: " + response; // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/StoppedException.java // public class StoppedException extends ResponseException { // // public StoppedException() { // super("STOPPED"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnableToConnectException.java // public class UnableToConnectException extends ResponseException { // // public UnableToConnectException() { // super("UNABLE TO CONNECT"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnknownErrorException.java // public class UnknownErrorException extends ResponseException { // // public UnknownErrorException() { // super("ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnsupportedCommandException.java // public class UnsupportedCommandException extends ResponseException { // // public UnsupportedCommandException() { // super("7F 0[0-9] 12", true); // } // // } // Path: app/src/main/java/org/hexpresso/elm327/commands/AbstractCommand.java import org.hexpresso.elm327.exceptions.BusInitException; import org.hexpresso.elm327.exceptions.MisunderstoodCommandException; import org.hexpresso.elm327.exceptions.NoDataException; import org.hexpresso.elm327.exceptions.ResponseException; import org.hexpresso.elm327.exceptions.StoppedException; import org.hexpresso.elm327.exceptions.UnableToConnectException; import org.hexpresso.elm327.exceptions.UnknownErrorException; import org.hexpresso.elm327.exceptions.UnsupportedCommandException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; package org.hexpresso.elm327.commands; /** * The AbstractCommand class represents an ELM327 command. * <p/> * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-24. */ public abstract class AbstractCommand implements Command { protected String mCommand = null; // ELM327 command protected long mResponseTimeDelay = 200; // Time delay before receiving the response, in milliseconds protected Response mResponse = new Response(); // Response object private long mRunStartTimestamp; // Timestamp before sending the command private long mRunEndTimestamp; // Timestamp after receiving the command response private boolean mWithAutoProcessResponse = false; // /** * Error classes to be tested in order */ private final static Class[] ERROR_CLASSES = { UnableToConnectException.class, BusInitException.class, MisunderstoodCommandException.class, NoDataException.class, StoppedException.class,
UnknownErrorException.class,
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/elm327/commands/AbstractCommand.java
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/BusInitException.java // public class BusInitException extends ResponseException { // // public BusInitException() { // super("BUS INIT... ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/MisunderstoodCommandException.java // public class MisunderstoodCommandException extends ResponseException { // // public MisunderstoodCommandException() { // super("?"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/NoDataException.java // public class NoDataException extends ResponseException { // // public NoDataException() { // super("NO DATA"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/ResponseException.java // public class ResponseException extends RuntimeException { // // private String message; // // private String response; // // private String command; // // private boolean matchRegex; // // /** // * @param message a {@link java.lang.String} object. // */ // protected ResponseException(String message) { // this.message = message; // } // // protected ResponseException(String message, boolean matchRegex) { // this.message = message; // this.matchRegex = matchRegex; // } // // private static String clean(String s) { // return s == null ? "" : s.replaceAll("\\s", "").toUpperCase(); // } // // /** // * @param response a {@link java.lang.String} object. // * @return a boolean. // */ // public boolean isError(String response) { // this.response = response; // if (matchRegex) { // return clean(response).matches(clean(message)); // } else { // return clean(response).contains(clean(message)); // } // } // // /** // * @param command a {@link java.lang.String} object. // */ // public void setCommand(String command) { // this.command = command; // } // // @Override // public String getMessage() { // return "Error running " + command + ", response: " + response; // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/StoppedException.java // public class StoppedException extends ResponseException { // // public StoppedException() { // super("STOPPED"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnableToConnectException.java // public class UnableToConnectException extends ResponseException { // // public UnableToConnectException() { // super("UNABLE TO CONNECT"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnknownErrorException.java // public class UnknownErrorException extends ResponseException { // // public UnknownErrorException() { // super("ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnsupportedCommandException.java // public class UnsupportedCommandException extends ResponseException { // // public UnsupportedCommandException() { // super("7F 0[0-9] 12", true); // } // // }
import org.hexpresso.elm327.exceptions.BusInitException; import org.hexpresso.elm327.exceptions.MisunderstoodCommandException; import org.hexpresso.elm327.exceptions.NoDataException; import org.hexpresso.elm327.exceptions.ResponseException; import org.hexpresso.elm327.exceptions.StoppedException; import org.hexpresso.elm327.exceptions.UnableToConnectException; import org.hexpresso.elm327.exceptions.UnknownErrorException; import org.hexpresso.elm327.exceptions.UnsupportedCommandException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream;
package org.hexpresso.elm327.commands; /** * The AbstractCommand class represents an ELM327 command. * <p/> * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-24. */ public abstract class AbstractCommand implements Command { protected String mCommand = null; // ELM327 command protected long mResponseTimeDelay = 200; // Time delay before receiving the response, in milliseconds protected Response mResponse = new Response(); // Response object private long mRunStartTimestamp; // Timestamp before sending the command private long mRunEndTimestamp; // Timestamp after receiving the command response private boolean mWithAutoProcessResponse = false; // /** * Error classes to be tested in order */ private final static Class[] ERROR_CLASSES = { UnableToConnectException.class, BusInitException.class, MisunderstoodCommandException.class, NoDataException.class, StoppedException.class, UnknownErrorException.class,
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/BusInitException.java // public class BusInitException extends ResponseException { // // public BusInitException() { // super("BUS INIT... ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/MisunderstoodCommandException.java // public class MisunderstoodCommandException extends ResponseException { // // public MisunderstoodCommandException() { // super("?"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/NoDataException.java // public class NoDataException extends ResponseException { // // public NoDataException() { // super("NO DATA"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/ResponseException.java // public class ResponseException extends RuntimeException { // // private String message; // // private String response; // // private String command; // // private boolean matchRegex; // // /** // * @param message a {@link java.lang.String} object. // */ // protected ResponseException(String message) { // this.message = message; // } // // protected ResponseException(String message, boolean matchRegex) { // this.message = message; // this.matchRegex = matchRegex; // } // // private static String clean(String s) { // return s == null ? "" : s.replaceAll("\\s", "").toUpperCase(); // } // // /** // * @param response a {@link java.lang.String} object. // * @return a boolean. // */ // public boolean isError(String response) { // this.response = response; // if (matchRegex) { // return clean(response).matches(clean(message)); // } else { // return clean(response).contains(clean(message)); // } // } // // /** // * @param command a {@link java.lang.String} object. // */ // public void setCommand(String command) { // this.command = command; // } // // @Override // public String getMessage() { // return "Error running " + command + ", response: " + response; // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/StoppedException.java // public class StoppedException extends ResponseException { // // public StoppedException() { // super("STOPPED"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnableToConnectException.java // public class UnableToConnectException extends ResponseException { // // public UnableToConnectException() { // super("UNABLE TO CONNECT"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnknownErrorException.java // public class UnknownErrorException extends ResponseException { // // public UnknownErrorException() { // super("ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnsupportedCommandException.java // public class UnsupportedCommandException extends ResponseException { // // public UnsupportedCommandException() { // super("7F 0[0-9] 12", true); // } // // } // Path: app/src/main/java/org/hexpresso/elm327/commands/AbstractCommand.java import org.hexpresso.elm327.exceptions.BusInitException; import org.hexpresso.elm327.exceptions.MisunderstoodCommandException; import org.hexpresso.elm327.exceptions.NoDataException; import org.hexpresso.elm327.exceptions.ResponseException; import org.hexpresso.elm327.exceptions.StoppedException; import org.hexpresso.elm327.exceptions.UnableToConnectException; import org.hexpresso.elm327.exceptions.UnknownErrorException; import org.hexpresso.elm327.exceptions.UnsupportedCommandException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; package org.hexpresso.elm327.commands; /** * The AbstractCommand class represents an ELM327 command. * <p/> * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-24. */ public abstract class AbstractCommand implements Command { protected String mCommand = null; // ELM327 command protected long mResponseTimeDelay = 200; // Time delay before receiving the response, in milliseconds protected Response mResponse = new Response(); // Response object private long mRunStartTimestamp; // Timestamp before sending the command private long mRunEndTimestamp; // Timestamp after receiving the command response private boolean mWithAutoProcessResponse = false; // /** * Error classes to be tested in order */ private final static Class[] ERROR_CLASSES = { UnableToConnectException.class, BusInitException.class, MisunderstoodCommandException.class, NoDataException.class, StoppedException.class, UnknownErrorException.class,
UnsupportedCommandException.class
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/elm327/commands/AbstractCommand.java
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/BusInitException.java // public class BusInitException extends ResponseException { // // public BusInitException() { // super("BUS INIT... ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/MisunderstoodCommandException.java // public class MisunderstoodCommandException extends ResponseException { // // public MisunderstoodCommandException() { // super("?"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/NoDataException.java // public class NoDataException extends ResponseException { // // public NoDataException() { // super("NO DATA"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/ResponseException.java // public class ResponseException extends RuntimeException { // // private String message; // // private String response; // // private String command; // // private boolean matchRegex; // // /** // * @param message a {@link java.lang.String} object. // */ // protected ResponseException(String message) { // this.message = message; // } // // protected ResponseException(String message, boolean matchRegex) { // this.message = message; // this.matchRegex = matchRegex; // } // // private static String clean(String s) { // return s == null ? "" : s.replaceAll("\\s", "").toUpperCase(); // } // // /** // * @param response a {@link java.lang.String} object. // * @return a boolean. // */ // public boolean isError(String response) { // this.response = response; // if (matchRegex) { // return clean(response).matches(clean(message)); // } else { // return clean(response).contains(clean(message)); // } // } // // /** // * @param command a {@link java.lang.String} object. // */ // public void setCommand(String command) { // this.command = command; // } // // @Override // public String getMessage() { // return "Error running " + command + ", response: " + response; // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/StoppedException.java // public class StoppedException extends ResponseException { // // public StoppedException() { // super("STOPPED"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnableToConnectException.java // public class UnableToConnectException extends ResponseException { // // public UnableToConnectException() { // super("UNABLE TO CONNECT"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnknownErrorException.java // public class UnknownErrorException extends ResponseException { // // public UnknownErrorException() { // super("ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnsupportedCommandException.java // public class UnsupportedCommandException extends ResponseException { // // public UnsupportedCommandException() { // super("7F 0[0-9] 12", true); // } // // }
import org.hexpresso.elm327.exceptions.BusInitException; import org.hexpresso.elm327.exceptions.MisunderstoodCommandException; import org.hexpresso.elm327.exceptions.NoDataException; import org.hexpresso.elm327.exceptions.ResponseException; import org.hexpresso.elm327.exceptions.StoppedException; import org.hexpresso.elm327.exceptions.UnableToConnectException; import org.hexpresso.elm327.exceptions.UnknownErrorException; import org.hexpresso.elm327.exceptions.UnsupportedCommandException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream;
/* * Imagine the following response 41 0c 00 0d. * * ELM sends strings!! So, ELM puts spaces between each "byte". And pay * attention to the fact that I've put the word byte in quotes, because 41 * is actually TWO bytes (two chars) in the socket. So, we must do some more * processing.. */ String rawResponse = res.toString(); rawResponse = rawResponse.replaceAll("SEARCHING", ""); // TODO check this //rawResponse = rawResponse.replaceAll("(BUS INIT)|(BUSINIT)|(\\.)", ""); /* * Data may have echo or informative text like "INIT BUS..." or similar. * The response ends with two carriage return characters. So we need to take * everything from the last carriage return before those two (trimmed above). */ //kills multiline.. rawData = rawData.substring(rawData.lastIndexOf(13) + 1); //mResponse = mResponse.replaceAll("\\s", "");//removes all [ \t\n\x0B\f\r] // Generate the Response object mResponse.setRawResponse(rawResponse); if (mWithAutoProcessResponse) { mResponse.process(); } } protected void checkForErrors() {
// Path: app/src/main/java/org/hexpresso/elm327/exceptions/BusInitException.java // public class BusInitException extends ResponseException { // // public BusInitException() { // super("BUS INIT... ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/MisunderstoodCommandException.java // public class MisunderstoodCommandException extends ResponseException { // // public MisunderstoodCommandException() { // super("?"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/NoDataException.java // public class NoDataException extends ResponseException { // // public NoDataException() { // super("NO DATA"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/ResponseException.java // public class ResponseException extends RuntimeException { // // private String message; // // private String response; // // private String command; // // private boolean matchRegex; // // /** // * @param message a {@link java.lang.String} object. // */ // protected ResponseException(String message) { // this.message = message; // } // // protected ResponseException(String message, boolean matchRegex) { // this.message = message; // this.matchRegex = matchRegex; // } // // private static String clean(String s) { // return s == null ? "" : s.replaceAll("\\s", "").toUpperCase(); // } // // /** // * @param response a {@link java.lang.String} object. // * @return a boolean. // */ // public boolean isError(String response) { // this.response = response; // if (matchRegex) { // return clean(response).matches(clean(message)); // } else { // return clean(response).contains(clean(message)); // } // } // // /** // * @param command a {@link java.lang.String} object. // */ // public void setCommand(String command) { // this.command = command; // } // // @Override // public String getMessage() { // return "Error running " + command + ", response: " + response; // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/StoppedException.java // public class StoppedException extends ResponseException { // // public StoppedException() { // super("STOPPED"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnableToConnectException.java // public class UnableToConnectException extends ResponseException { // // public UnableToConnectException() { // super("UNABLE TO CONNECT"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnknownErrorException.java // public class UnknownErrorException extends ResponseException { // // public UnknownErrorException() { // super("ERROR"); // } // // } // // Path: app/src/main/java/org/hexpresso/elm327/exceptions/UnsupportedCommandException.java // public class UnsupportedCommandException extends ResponseException { // // public UnsupportedCommandException() { // super("7F 0[0-9] 12", true); // } // // } // Path: app/src/main/java/org/hexpresso/elm327/commands/AbstractCommand.java import org.hexpresso.elm327.exceptions.BusInitException; import org.hexpresso.elm327.exceptions.MisunderstoodCommandException; import org.hexpresso.elm327.exceptions.NoDataException; import org.hexpresso.elm327.exceptions.ResponseException; import org.hexpresso.elm327.exceptions.StoppedException; import org.hexpresso.elm327.exceptions.UnableToConnectException; import org.hexpresso.elm327.exceptions.UnknownErrorException; import org.hexpresso.elm327.exceptions.UnsupportedCommandException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; /* * Imagine the following response 41 0c 00 0d. * * ELM sends strings!! So, ELM puts spaces between each "byte". And pay * attention to the fact that I've put the word byte in quotes, because 41 * is actually TWO bytes (two chars) in the socket. So, we must do some more * processing.. */ String rawResponse = res.toString(); rawResponse = rawResponse.replaceAll("SEARCHING", ""); // TODO check this //rawResponse = rawResponse.replaceAll("(BUS INIT)|(BUSINIT)|(\\.)", ""); /* * Data may have echo or informative text like "INIT BUS..." or similar. * The response ends with two carriage return characters. So we need to take * everything from the last carriage return before those two (trimmed above). */ //kills multiline.. rawData = rawData.substring(rawData.lastIndexOf(13) + 1); //mResponse = mResponse.replaceAll("\\s", "");//removes all [ \t\n\x0B\f\r] // Generate the Response object mResponse.setRawResponse(rawResponse); if (mWithAutoProcessResponse) { mResponse.process(); } } protected void checkForErrors() {
for (Class<? extends ResponseException> errorClass : ERROR_CLASSES) {
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/soulevspy/obd/ParkingBrakeMessageFilter.java
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // }
import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter; import java.util.ArrayList;
package org.hexpresso.soulevspy.obd; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-13. */ public class ParkingBrakeMessageFilter extends ObdMessageFilter { boolean mIsParkingBrakeOn = false; public ParkingBrakeMessageFilter() { super("433"); } @Override
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // } // Path: app/src/main/java/org/hexpresso/soulevspy/obd/ParkingBrakeMessageFilter.java import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter; import java.util.ArrayList; package org.hexpresso.soulevspy.obd; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-13. */ public class ParkingBrakeMessageFilter extends ObdMessageFilter { boolean mIsParkingBrakeOn = false; public ParkingBrakeMessageFilter() { super("433"); } @Override
protected boolean doProcessMessage(ObdMessageData messageData) {
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/soulevspy/obd/ClockMessageFilter.java
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // }
import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter; import java.util.ArrayList; import java.util.Calendar; import java.util.GregorianCalendar;
package org.hexpresso.soulevspy.obd; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-13. */ public class ClockMessageFilter extends ObdMessageFilter { GregorianCalendar mTime = null; public ClockMessageFilter() { super("567"); } @Override
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // } // Path: app/src/main/java/org/hexpresso/soulevspy/obd/ClockMessageFilter.java import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter; import java.util.ArrayList; import java.util.Calendar; import java.util.GregorianCalendar; package org.hexpresso.soulevspy.obd; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-13. */ public class ClockMessageFilter extends ObdMessageFilter { GregorianCalendar mTime = null; public ClockMessageFilter() { super("567"); } @Override
protected boolean doProcessMessage(ObdMessageData messageData) {
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/soulevspy/obd/StateOfChargePreciseMessageFilter.java
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // }
import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter; import java.util.ArrayList;
package org.hexpresso.soulevspy.obd; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-13. */ public class StateOfChargePreciseMessageFilter extends ObdMessageFilter { double mSOCValue = 0.0; public StateOfChargePreciseMessageFilter() { super("598"); } @Override
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // } // Path: app/src/main/java/org/hexpresso/soulevspy/obd/StateOfChargePreciseMessageFilter.java import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter; import java.util.ArrayList; package org.hexpresso.soulevspy.obd; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-13. */ public class StateOfChargePreciseMessageFilter extends ObdMessageFilter { double mSOCValue = 0.0; public StateOfChargePreciseMessageFilter() { super("598"); } @Override
protected boolean doProcessMessage(ObdMessageData messageData) {
pemessier/SoulEVSpy
app/src/androidTest/java/org/hexpresso/soulevspy/obd/AmbientTempMessageFilterTest.java
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // }
import junit.framework.TestCase; import org.hexpresso.obd.ObdMessageData;
package org.hexpresso.soulevspy.obd; /** * Created by Tyrel Haveman <[email protected]> on 11/30/2015. */ public class AmbientTempMessageFilterTest extends TestCase { public void testGetsTemperature() { AmbientTempMessageFilter filter = new AmbientTempMessageFilter();
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // Path: app/src/androidTest/java/org/hexpresso/soulevspy/obd/AmbientTempMessageFilterTest.java import junit.framework.TestCase; import org.hexpresso.obd.ObdMessageData; package org.hexpresso.soulevspy.obd; /** * Created by Tyrel Haveman <[email protected]> on 11/30/2015. */ public class AmbientTempMessageFilterTest extends TestCase { public void testGetsTemperature() { AmbientTempMessageFilter filter = new AmbientTempMessageFilter();
ObdMessageData messageData = new ObdMessageData("653 00 1E 00 00 00 74 00 00");
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/elm327/io/bluetooth/BluetoothService.java
// Path: app/src/main/java/org/hexpresso/elm327/io/Service.java // public abstract class Service { // // // TODO handle high level service here, then we can have 2 ELM327 flavors : Bluetooth and WiFi // // private ServiceStateListener mServiceStateListener = null; // // private Protocol mProtocol = null; // // private ServiceStates mState = ServiceStates.STATE_DISCONNECTED; // protected InputStream mInputStream = null; // protected OutputStream mOutputStream = null; // // /** // * Constructor // */ // protected Service() { // } // // public interface ServiceStateListener { // void onServiceStateChanged(ServiceStates state); // } // // /** // * Connects to the ELM327 device // */ // public abstract void connect(); // // /** // * Disconnects from the ELM327 device // */ // public abstract void disconnect(); // // /** // * Returns the current Service state // * // * @return current Service state. // */ // public synchronized ServiceStates getState() { // return mState; // } // // /** // * Updates the Service state to the specified state. If a ServiceStateListener is available, it // * will be notified. // * // * @param state new Service state to be set // */ // protected synchronized void setState(final ServiceStates state) { // mState = state; // // // Notify the listeners, if any // if( mServiceStateListener != null) { // Thread notificationThread = new Thread(new Runnable() { // @Override // public void run() { // mServiceStateListener.onServiceStateChanged(state); // } // }); // notificationThread.start(); // } // } // // /** // * Close the input and output streams if open // */ // protected void closeStreams() { // if(mInputStream != null) { // try { // mInputStream.close(); // } catch (IOException e) { // } // } // // if(mOutputStream != null) { // try { // mOutputStream.close(); // } catch (IOException e) { // } // } // } // // protected void startProtocol() { // // TODO verify streams not null // if(mState == ServiceStates.STATE_CONNECTED) { // mProtocol = new Protocol(); // mProtocol.start(mInputStream, mOutputStream); // } // } // // protected void stopProtocol() { // if(mProtocol != null) { // mProtocol.stop(); // } // } // // Protocol getProtocol() { // return mProtocol; // } // // public void setServiceStateListener(ServiceStateListener listener) { // mServiceStateListener = listener; // } // } // // Path: app/src/main/java/org/hexpresso/elm327/io/ServiceStates.java // public enum ServiceStates { // /** // * The service is in connecting state // */ // STATE_CONNECTING, // // /** // * The service is in connected state // */ // STATE_CONNECTED, // // /** // * The service is in disconnecting state // */ // STATE_DISCONNECTING, // // /** // * The service is in disconnected state // */ // STATE_DISCONNECTED // }
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothSocket; import org.hexpresso.elm327.io.Service; import org.hexpresso.elm327.io.ServiceStates; import java.io.IOException; import java.util.UUID;
package org.hexpresso.elm327.io.bluetooth; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-30. */ public class BluetoothService extends Service { // We are connecting to a Bluetooth serial board, therefore we use the well-known SPP UUID private static final UUID SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); private final BluetoothAdapter mBluetoothAdapter; private BluetoothDevice mBluetoothDevice = null; private BluetoothSocket mBluetoothSocket = null; private boolean mUseSecureConnection = true; private Boolean mBluetoothAvailable = null; /** * Constructor */ public BluetoothService() { super(); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); } /** * Sets the Bluetooth address of the device to use for connection * * @param address Device Bluetooth address as string */ public void setDevice(String address) { mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(address); } /** * Connects to the ELM327 device */ @Override public synchronized void connect() { // TODO prevent dual connect? if(isBluetoothAvailable()) { Thread connectionThread = new Thread(new Runnable() { @Override public void run() { // Make sure we are disconnected first internalDisconnect(); // Start the connection routine internalConnect(); } }); connectionThread.start(); } } /** * Connection routine */ private void internalConnect() {
// Path: app/src/main/java/org/hexpresso/elm327/io/Service.java // public abstract class Service { // // // TODO handle high level service here, then we can have 2 ELM327 flavors : Bluetooth and WiFi // // private ServiceStateListener mServiceStateListener = null; // // private Protocol mProtocol = null; // // private ServiceStates mState = ServiceStates.STATE_DISCONNECTED; // protected InputStream mInputStream = null; // protected OutputStream mOutputStream = null; // // /** // * Constructor // */ // protected Service() { // } // // public interface ServiceStateListener { // void onServiceStateChanged(ServiceStates state); // } // // /** // * Connects to the ELM327 device // */ // public abstract void connect(); // // /** // * Disconnects from the ELM327 device // */ // public abstract void disconnect(); // // /** // * Returns the current Service state // * // * @return current Service state. // */ // public synchronized ServiceStates getState() { // return mState; // } // // /** // * Updates the Service state to the specified state. If a ServiceStateListener is available, it // * will be notified. // * // * @param state new Service state to be set // */ // protected synchronized void setState(final ServiceStates state) { // mState = state; // // // Notify the listeners, if any // if( mServiceStateListener != null) { // Thread notificationThread = new Thread(new Runnable() { // @Override // public void run() { // mServiceStateListener.onServiceStateChanged(state); // } // }); // notificationThread.start(); // } // } // // /** // * Close the input and output streams if open // */ // protected void closeStreams() { // if(mInputStream != null) { // try { // mInputStream.close(); // } catch (IOException e) { // } // } // // if(mOutputStream != null) { // try { // mOutputStream.close(); // } catch (IOException e) { // } // } // } // // protected void startProtocol() { // // TODO verify streams not null // if(mState == ServiceStates.STATE_CONNECTED) { // mProtocol = new Protocol(); // mProtocol.start(mInputStream, mOutputStream); // } // } // // protected void stopProtocol() { // if(mProtocol != null) { // mProtocol.stop(); // } // } // // Protocol getProtocol() { // return mProtocol; // } // // public void setServiceStateListener(ServiceStateListener listener) { // mServiceStateListener = listener; // } // } // // Path: app/src/main/java/org/hexpresso/elm327/io/ServiceStates.java // public enum ServiceStates { // /** // * The service is in connecting state // */ // STATE_CONNECTING, // // /** // * The service is in connected state // */ // STATE_CONNECTED, // // /** // * The service is in disconnecting state // */ // STATE_DISCONNECTING, // // /** // * The service is in disconnected state // */ // STATE_DISCONNECTED // } // Path: app/src/main/java/org/hexpresso/elm327/io/bluetooth/BluetoothService.java import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothSocket; import org.hexpresso.elm327.io.Service; import org.hexpresso.elm327.io.ServiceStates; import java.io.IOException; import java.util.UUID; package org.hexpresso.elm327.io.bluetooth; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-30. */ public class BluetoothService extends Service { // We are connecting to a Bluetooth serial board, therefore we use the well-known SPP UUID private static final UUID SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); private final BluetoothAdapter mBluetoothAdapter; private BluetoothDevice mBluetoothDevice = null; private BluetoothSocket mBluetoothSocket = null; private boolean mUseSecureConnection = true; private Boolean mBluetoothAvailable = null; /** * Constructor */ public BluetoothService() { super(); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); } /** * Sets the Bluetooth address of the device to use for connection * * @param address Device Bluetooth address as string */ public void setDevice(String address) { mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(address); } /** * Connects to the ELM327 device */ @Override public synchronized void connect() { // TODO prevent dual connect? if(isBluetoothAvailable()) { Thread connectionThread = new Thread(new Runnable() { @Override public void run() { // Make sure we are disconnected first internalDisconnect(); // Start the connection routine internalConnect(); } }); connectionThread.start(); } } /** * Connection routine */ private void internalConnect() {
setState(ServiceStates.STATE_CONNECTING);
pemessier/SoulEVSpy
app/src/androidTest/java/org/hexpresso/soulevspy/obd/SpeedPreciseMessageFilterTest.java
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // }
import android.test.AndroidTestCase; import junit.framework.Assert; import org.hexpresso.obd.ObdMessageData;
package org.hexpresso.soulevspy.obd; /** * Created by Tyrel on 10/17/2015. */ public class SpeedPreciseMessageFilterTest extends AndroidTestCase { public void testProcessesZero() { SpeedPreciseMessageFilter filter = new SpeedPreciseMessageFilter();
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // Path: app/src/androidTest/java/org/hexpresso/soulevspy/obd/SpeedPreciseMessageFilterTest.java import android.test.AndroidTestCase; import junit.framework.Assert; import org.hexpresso.obd.ObdMessageData; package org.hexpresso.soulevspy.obd; /** * Created by Tyrel on 10/17/2015. */ public class SpeedPreciseMessageFilterTest extends AndroidTestCase { public void testProcessesZero() { SpeedPreciseMessageFilter filter = new SpeedPreciseMessageFilter();
ObdMessageData messageData = new ObdMessageData("4F2 01 00 00 10 00 00 80 00");
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/soulevspy/obd/SpeedPreciseMessageFilter.java
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // }
import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter; import java.util.ArrayList;
package org.hexpresso.soulevspy.obd; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-13. */ public class SpeedPreciseMessageFilter extends ObdMessageFilter { double mSpeedKmH = 0.0; public SpeedPreciseMessageFilter() { super("4F2"); }
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // } // Path: app/src/main/java/org/hexpresso/soulevspy/obd/SpeedPreciseMessageFilter.java import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter; import java.util.ArrayList; package org.hexpresso.soulevspy.obd; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-13. */ public class SpeedPreciseMessageFilter extends ObdMessageFilter { double mSpeedKmH = 0.0; public SpeedPreciseMessageFilter() { super("4F2"); }
protected boolean doProcessMessage(ObdMessageData messageData) {
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/soulevspy/obd/AmbientTempMessageFilter.java
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // }
import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter;
package org.hexpresso.soulevspy.obd; /** * Created by Tyrel Haveman <[email protected]> on 11/30/2015. */ public class AmbientTempMessageFilter extends ObdMessageFilter { private double ambientTemperature; public AmbientTempMessageFilter() { super("653"); } @Override
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // } // Path: app/src/main/java/org/hexpresso/soulevspy/obd/AmbientTempMessageFilter.java import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter; package org.hexpresso.soulevspy.obd; /** * Created by Tyrel Haveman <[email protected]> on 11/30/2015. */ public class AmbientTempMessageFilter extends ObdMessageFilter { private double ambientTemperature; public AmbientTempMessageFilter() { super("653"); } @Override
protected boolean doProcessMessage(ObdMessageData messageData) {
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/soulevspy/obd/Status050MessageFilter.java
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // }
import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter; import java.util.ArrayList;
INTER_1, INTER_2, INTER_3, INTER_4, // Fastest NORMAL, FAST } public enum LightsMode { OFF, PARKING, ON, AUTOMATIC } private TurnSignal mTurnSignal = TurnSignal.OFF; private LightsMode mLightsMode = LightsMode.OFF; private WiperSpeed mWiperSpeed = WiperSpeed.OFF; public Status050MessageFilter() { super("050"); } private static final int MASK_LIGHTS = 0x03; private static final int MASK_WIPERS_INTER = 0xF0; private static final int MASK_WIPERS = 0x07; private static final int MASK_TURN_SIGNAL = 0x30; @Override
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // } // Path: app/src/main/java/org/hexpresso/soulevspy/obd/Status050MessageFilter.java import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter; import java.util.ArrayList; INTER_1, INTER_2, INTER_3, INTER_4, // Fastest NORMAL, FAST } public enum LightsMode { OFF, PARKING, ON, AUTOMATIC } private TurnSignal mTurnSignal = TurnSignal.OFF; private LightsMode mLightsMode = LightsMode.OFF; private WiperSpeed mWiperSpeed = WiperSpeed.OFF; public Status050MessageFilter() { super("050"); } private static final int MASK_LIGHTS = 0x03; private static final int MASK_WIPERS_INTER = 0xF0; private static final int MASK_WIPERS = 0x07; private static final int MASK_TURN_SIGNAL = 0x30; @Override
protected boolean doProcessMessage(ObdMessageData messageData) {
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/soulevspy/obd/OdometerMessageFilter.java
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // }
import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter;
package org.hexpresso.soulevspy.obd; /** * Created by Tyrel on 10/17/2015. */ public class OdometerMessageFilter extends ObdMessageFilter { double odometerKM; public OdometerMessageFilter() { super("4F0"); } @Override
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // } // Path: app/src/main/java/org/hexpresso/soulevspy/obd/OdometerMessageFilter.java import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter; package org.hexpresso.soulevspy.obd; /** * Created by Tyrel on 10/17/2015. */ public class OdometerMessageFilter extends ObdMessageFilter { double odometerKM; public OdometerMessageFilter() { super("4F0"); } @Override
protected boolean doProcessMessage(ObdMessageData messageData) {
pemessier/SoulEVSpy
app/src/main/java/org/hexpresso/soulevspy/obd/BatteryChargingMessageFilter.java
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // }
import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter; import java.util.ArrayList;
package org.hexpresso.soulevspy.obd; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-13. */ public class BatteryChargingMessageFilter extends ObdMessageFilter { public enum ConnectedChargerType { NONE, TYPE1, J1772, CHADEMO } private boolean mIsCharging = false; private ConnectedChargerType mChargerType = ConnectedChargerType.NONE; private double mChargingPowerKW = 0.0; public BatteryChargingMessageFilter() { super("581"); } @Override
// Path: app/src/main/java/org/hexpresso/obd/ObdMessageData.java // public class ObdMessageData { // private ArrayList<String> mData = null; // private String mRawData = null; // private String mMessageIdentifier = null; // // public ObdMessageData(String rawData) { // // Remove all whitespace characters but ' ' // rawData = rawData.replaceAll("[\\t\\n\\x0B\\f\\r]", ""); // // // Split the data into items // String[] data = rawData.split("\\s"); // if ( data.length == 0 ) // { // return; // } // // // Get the message identifier (first value) // mMessageIdentifier = data[0]; // // // Get the message data (other values) // mData = new ArrayList<>(); // for( int i = 1; i < data.length; ++i ) { // // Only keep 2 bytes data values (remove "<DATA ERROR" values) // String item = data[i]; // if ( item.length() == 2 ) { // mData.add(data[i]); // } // } // // mRawData = rawData; // /* // if (!rawData.matches("([0-9A-F])+")) { // throw new NonNumericResponseException(rawData); // } // */ // } // // public String getMessageIdentifier() { // return mMessageIdentifier; // } // // public String getRawData() { // return mRawData; // } // // public ArrayList<String> getData() { // return mData; // } // // public int getSize() // { // return mData.size(); // } // // public int getDataByte(int index) { // return Integer.parseInt(mData.get(index), 16); // } // } // // Path: app/src/main/java/org/hexpresso/obd/ObdMessageFilter.java // public abstract class ObdMessageFilter { // // private String mMessageIdentifier = null; // private ArrayList<ObdMessageFilterListener> mObdMessageFilterListeners = null; // // private ObdMessageFilter() { // // } // // protected ObdMessageFilter(String messageIdentifier) { // mObdMessageFilterListeners = new ArrayList<>(); // mMessageIdentifier = messageIdentifier; // } // // public void receive(String rawData) // { // // Check that the message identifier match // if ( !rawData.startsWith( mMessageIdentifier ) ) // { // return; // } // // ObdMessageData obdMessage = new ObdMessageData(rawData); // // if ( doProcessMessage(obdMessage) ) // { // for (ObdMessageFilterListener listener: mObdMessageFilterListeners) { // listener.onMessageReceived(this); // } // } // } // // protected abstract boolean doProcessMessage(ObdMessageData messageData); // // // public interface ObdMessageFilterListener { // void onMessageReceived(ObdMessageFilter messageFilter); // } // // public void addObdMessageFilterListener(ObdMessageFilterListener listener) { // mObdMessageFilterListeners.add(listener); // } // } // Path: app/src/main/java/org/hexpresso/soulevspy/obd/BatteryChargingMessageFilter.java import org.hexpresso.obd.ObdMessageData; import org.hexpresso.obd.ObdMessageFilter; import java.util.ArrayList; package org.hexpresso.soulevspy.obd; /** * Created by Pierre-Etienne Messier <[email protected]> on 2015-10-13. */ public class BatteryChargingMessageFilter extends ObdMessageFilter { public enum ConnectedChargerType { NONE, TYPE1, J1772, CHADEMO } private boolean mIsCharging = false; private ConnectedChargerType mChargerType = ConnectedChargerType.NONE; private double mChargingPowerKW = 0.0; public BatteryChargingMessageFilter() { super("581"); } @Override
protected boolean doProcessMessage(ObdMessageData messageData) {
ajitsing/Sherlock
sherlock/src/androidTest/java/com/singhajit/sherlock/core/database/DatabaseResetRule.java
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/Sherlock.java // public class Sherlock { // private static final String TAG = Sherlock.class.getSimpleName(); // private static Sherlock instance; // private final SherlockDatabaseHelper database; // private final CrashReporter crashReporter; // private AppInfoProvider appInfoProvider; // // private Sherlock(Context context) { // database = new SherlockDatabaseHelper(context); // crashReporter = new CrashReporter(context); // appInfoProvider = new DefaultAppInfoProvider(context); // } // // public static void init(final Context context) { // Log.d(TAG, "Initializing Sherlock..."); // instance = new Sherlock(context); // // final Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler(); // // Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { // @Override // public void uncaughtException(Thread thread, Throwable throwable) { // analyzeAndReportCrash(throwable); // handler.uncaughtException(thread, throwable); // } // }); // } // // public static boolean isInitialized() { // return instance != null; // } // // public static Sherlock getInstance() { // if (!isInitialized()) { // throw new SherlockNotInitializedException(); // } // Log.d(TAG, "Returning existing instance..."); // return instance; // } // // public List<Crash> getAllCrashes() { // return getInstance().database.getCrashes(); // } // // private static void analyzeAndReportCrash(Throwable throwable) { // Log.d(TAG, "Analyzing Crash..."); // CrashAnalyzer crashAnalyzer = new CrashAnalyzer(throwable); // Crash crash = crashAnalyzer.getAnalysis(); // int crashId = instance.database.insertCrash(CrashRecord.createFrom(crash)); // crash.setId(crashId); // instance.crashReporter.report(new CrashViewModel(crash)); // Log.d(TAG, "Crash analysis completed!"); // } // // public static void setAppInfoProvider(AppInfoProvider appInfoProvider) { // getInstance().appInfoProvider = appInfoProvider; // } // // public AppInfoProvider getAppInfoProvider() { // return getInstance().appInfoProvider; // } // }
import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.support.test.InstrumentationRegistry; import com.singhajit.sherlock.core.Sherlock; import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement;
package com.singhajit.sherlock.core.database; public class DatabaseResetRule implements TestRule { @Override public Statement apply(final Statement base, Description description) { return new Statement() { @Override public void evaluate() throws Throwable { resetDB(); initializeSherlock(); base.evaluate(); } }; } private void initializeSherlock() { Context targetContext = InstrumentationRegistry.getTargetContext();
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/Sherlock.java // public class Sherlock { // private static final String TAG = Sherlock.class.getSimpleName(); // private static Sherlock instance; // private final SherlockDatabaseHelper database; // private final CrashReporter crashReporter; // private AppInfoProvider appInfoProvider; // // private Sherlock(Context context) { // database = new SherlockDatabaseHelper(context); // crashReporter = new CrashReporter(context); // appInfoProvider = new DefaultAppInfoProvider(context); // } // // public static void init(final Context context) { // Log.d(TAG, "Initializing Sherlock..."); // instance = new Sherlock(context); // // final Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler(); // // Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { // @Override // public void uncaughtException(Thread thread, Throwable throwable) { // analyzeAndReportCrash(throwable); // handler.uncaughtException(thread, throwable); // } // }); // } // // public static boolean isInitialized() { // return instance != null; // } // // public static Sherlock getInstance() { // if (!isInitialized()) { // throw new SherlockNotInitializedException(); // } // Log.d(TAG, "Returning existing instance..."); // return instance; // } // // public List<Crash> getAllCrashes() { // return getInstance().database.getCrashes(); // } // // private static void analyzeAndReportCrash(Throwable throwable) { // Log.d(TAG, "Analyzing Crash..."); // CrashAnalyzer crashAnalyzer = new CrashAnalyzer(throwable); // Crash crash = crashAnalyzer.getAnalysis(); // int crashId = instance.database.insertCrash(CrashRecord.createFrom(crash)); // crash.setId(crashId); // instance.crashReporter.report(new CrashViewModel(crash)); // Log.d(TAG, "Crash analysis completed!"); // } // // public static void setAppInfoProvider(AppInfoProvider appInfoProvider) { // getInstance().appInfoProvider = appInfoProvider; // } // // public AppInfoProvider getAppInfoProvider() { // return getInstance().appInfoProvider; // } // } // Path: sherlock/src/androidTest/java/com/singhajit/sherlock/core/database/DatabaseResetRule.java import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.support.test.InstrumentationRegistry; import com.singhajit.sherlock.core.Sherlock; import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; package com.singhajit.sherlock.core.database; public class DatabaseResetRule implements TestRule { @Override public Statement apply(final Statement base, Description description) { return new Statement() { @Override public void evaluate() throws Throwable { resetDB(); initializeSherlock(); base.evaluate(); } }; } private void initializeSherlock() { Context targetContext = InstrumentationRegistry.getTargetContext();
Sherlock.init(targetContext);
ajitsing/Sherlock
sherlock/src/main/java/com/singhajit/sherlock/crashes/viewmodel/AppInfoViewModel.java
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/AppInfo.java // public class AppInfo { // private List<Pair> appDetails = new ArrayList<>(); // // private AppInfo(List<Pair> appDetails) { // this.appDetails = appDetails; // } // // public Map<String, String> getAppDetails() { // TreeMap<String, String> details = new TreeMap<>(); // for (Pair pair : appDetails) { // details.put(pair.getKey(), pair.getVal()); // } // return details.descendingMap(); // } // // public static class Builder { // List<Pair> appDetails = new ArrayList<>(); // // public Builder with(String key, String value) { // appDetails.add(new Pair(key, value)); // return this; // } // // public AppInfo build() { // return new AppInfo(appDetails); // } // } // }
import com.singhajit.sherlock.core.investigation.AppInfo; import java.util.ArrayList; import java.util.List; import java.util.Map;
package com.singhajit.sherlock.crashes.viewmodel; public class AppInfoViewModel { private ArrayList<AppInfoRowViewModel> appInfoRowViewModels;
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/AppInfo.java // public class AppInfo { // private List<Pair> appDetails = new ArrayList<>(); // // private AppInfo(List<Pair> appDetails) { // this.appDetails = appDetails; // } // // public Map<String, String> getAppDetails() { // TreeMap<String, String> details = new TreeMap<>(); // for (Pair pair : appDetails) { // details.put(pair.getKey(), pair.getVal()); // } // return details.descendingMap(); // } // // public static class Builder { // List<Pair> appDetails = new ArrayList<>(); // // public Builder with(String key, String value) { // appDetails.add(new Pair(key, value)); // return this; // } // // public AppInfo build() { // return new AppInfo(appDetails); // } // } // } // Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/viewmodel/AppInfoViewModel.java import com.singhajit.sherlock.core.investigation.AppInfo; import java.util.ArrayList; import java.util.List; import java.util.Map; package com.singhajit.sherlock.crashes.viewmodel; public class AppInfoViewModel { private ArrayList<AppInfoRowViewModel> appInfoRowViewModels;
public AppInfoViewModel(AppInfo appInfo) {
ajitsing/Sherlock
sherlock/src/main/java/com/singhajit/sherlock/core/database/CrashRecord.java
// Path: sherlock-no-op/src/main/java/com/singhajit/sherlock/core/investigation/Crash.java // public class Crash { // public static final String DATE_FORMAT = "EEE MMM dd kk:mm:ss z yyyy"; // // public Crash(String place, String reason, String stackTrace) { // } // // public Crash(int id, String placeOfCrash, String reasonOfCrash, String stacktrace, String date) { // } // // public DeviceInfo getDeviceInfo() { // return new DeviceInfo.Builder().build(); // } // // public AppInfo getAppInfo() { // return new AppInfo(); // } // // public void setId(int id) { // } // // public Class<Crash> getType() { // return Crash.class; // } // // public String getReason() { // return ""; // } // // public String getStackTrace() { // return ""; // } // // public String getPlace() { // return ""; // } // // public int getId() { // return 0; // } // // public Date getDate() { // return new Date(); // } // }
import com.singhajit.sherlock.core.investigation.Crash; import java.text.SimpleDateFormat;
package com.singhajit.sherlock.core.database; public class CrashRecord { private String place; private String reason; private String date; private String stackTrace; public CrashRecord(String place, String reason, String date, String stackTrace) { this.place = place; this.reason = reason; this.date = date; this.stackTrace = stackTrace; } public String getPlace() { return place; } public String getReason() { return reason; } public String getDate() { return date; } public String getStackTrace() { return stackTrace; }
// Path: sherlock-no-op/src/main/java/com/singhajit/sherlock/core/investigation/Crash.java // public class Crash { // public static final String DATE_FORMAT = "EEE MMM dd kk:mm:ss z yyyy"; // // public Crash(String place, String reason, String stackTrace) { // } // // public Crash(int id, String placeOfCrash, String reasonOfCrash, String stacktrace, String date) { // } // // public DeviceInfo getDeviceInfo() { // return new DeviceInfo.Builder().build(); // } // // public AppInfo getAppInfo() { // return new AppInfo(); // } // // public void setId(int id) { // } // // public Class<Crash> getType() { // return Crash.class; // } // // public String getReason() { // return ""; // } // // public String getStackTrace() { // return ""; // } // // public String getPlace() { // return ""; // } // // public int getId() { // return 0; // } // // public Date getDate() { // return new Date(); // } // } // Path: sherlock/src/main/java/com/singhajit/sherlock/core/database/CrashRecord.java import com.singhajit.sherlock.core.investigation.Crash; import java.text.SimpleDateFormat; package com.singhajit.sherlock.core.database; public class CrashRecord { private String place; private String reason; private String date; private String stackTrace; public CrashRecord(String place, String reason, String date, String stackTrace) { this.place = place; this.reason = reason; this.date = date; this.stackTrace = stackTrace; } public String getPlace() { return place; } public String getReason() { return reason; } public String getDate() { return date; } public String getStackTrace() { return stackTrace; }
public static CrashRecord createFrom(Crash crash) {
ajitsing/Sherlock
sherlock/src/main/java/com/singhajit/sherlock/core/investigation/Crash.java
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/Sherlock.java // public class Sherlock { // private static final String TAG = Sherlock.class.getSimpleName(); // private static Sherlock instance; // private final SherlockDatabaseHelper database; // private final CrashReporter crashReporter; // private AppInfoProvider appInfoProvider; // // private Sherlock(Context context) { // database = new SherlockDatabaseHelper(context); // crashReporter = new CrashReporter(context); // appInfoProvider = new DefaultAppInfoProvider(context); // } // // public static void init(final Context context) { // Log.d(TAG, "Initializing Sherlock..."); // instance = new Sherlock(context); // // final Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler(); // // Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { // @Override // public void uncaughtException(Thread thread, Throwable throwable) { // analyzeAndReportCrash(throwable); // handler.uncaughtException(thread, throwable); // } // }); // } // // public static boolean isInitialized() { // return instance != null; // } // // public static Sherlock getInstance() { // if (!isInitialized()) { // throw new SherlockNotInitializedException(); // } // Log.d(TAG, "Returning existing instance..."); // return instance; // } // // public List<Crash> getAllCrashes() { // return getInstance().database.getCrashes(); // } // // private static void analyzeAndReportCrash(Throwable throwable) { // Log.d(TAG, "Analyzing Crash..."); // CrashAnalyzer crashAnalyzer = new CrashAnalyzer(throwable); // Crash crash = crashAnalyzer.getAnalysis(); // int crashId = instance.database.insertCrash(CrashRecord.createFrom(crash)); // crash.setId(crashId); // instance.crashReporter.report(new CrashViewModel(crash)); // Log.d(TAG, "Crash analysis completed!"); // } // // public static void setAppInfoProvider(AppInfoProvider appInfoProvider) { // getInstance().appInfoProvider = appInfoProvider; // } // // public AppInfoProvider getAppInfoProvider() { // return getInstance().appInfoProvider; // } // }
import com.singhajit.sherlock.core.Sherlock; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale;
package com.singhajit.sherlock.core.investigation; public class Crash { private int id; private DeviceInfo deviceInfo; private AppInfo appInfo; private String place; private String reason; private String stackTrace; private Date date; public static final String DATE_FORMAT = "EEE MMM dd kk:mm:ss z yyyy"; public Crash(String place, String reason, String stackTrace) { this.place = place; this.stackTrace = stackTrace; this.reason = reason; this.date = new Date(); this.deviceInfo = DeviceInfoProvider.getDeviceInfo();
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/Sherlock.java // public class Sherlock { // private static final String TAG = Sherlock.class.getSimpleName(); // private static Sherlock instance; // private final SherlockDatabaseHelper database; // private final CrashReporter crashReporter; // private AppInfoProvider appInfoProvider; // // private Sherlock(Context context) { // database = new SherlockDatabaseHelper(context); // crashReporter = new CrashReporter(context); // appInfoProvider = new DefaultAppInfoProvider(context); // } // // public static void init(final Context context) { // Log.d(TAG, "Initializing Sherlock..."); // instance = new Sherlock(context); // // final Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler(); // // Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { // @Override // public void uncaughtException(Thread thread, Throwable throwable) { // analyzeAndReportCrash(throwable); // handler.uncaughtException(thread, throwable); // } // }); // } // // public static boolean isInitialized() { // return instance != null; // } // // public static Sherlock getInstance() { // if (!isInitialized()) { // throw new SherlockNotInitializedException(); // } // Log.d(TAG, "Returning existing instance..."); // return instance; // } // // public List<Crash> getAllCrashes() { // return getInstance().database.getCrashes(); // } // // private static void analyzeAndReportCrash(Throwable throwable) { // Log.d(TAG, "Analyzing Crash..."); // CrashAnalyzer crashAnalyzer = new CrashAnalyzer(throwable); // Crash crash = crashAnalyzer.getAnalysis(); // int crashId = instance.database.insertCrash(CrashRecord.createFrom(crash)); // crash.setId(crashId); // instance.crashReporter.report(new CrashViewModel(crash)); // Log.d(TAG, "Crash analysis completed!"); // } // // public static void setAppInfoProvider(AppInfoProvider appInfoProvider) { // getInstance().appInfoProvider = appInfoProvider; // } // // public AppInfoProvider getAppInfoProvider() { // return getInstance().appInfoProvider; // } // } // Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/Crash.java import com.singhajit.sherlock.core.Sherlock; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; package com.singhajit.sherlock.core.investigation; public class Crash { private int id; private DeviceInfo deviceInfo; private AppInfo appInfo; private String place; private String reason; private String stackTrace; private Date date; public static final String DATE_FORMAT = "EEE MMM dd kk:mm:ss z yyyy"; public Crash(String place, String reason, String stackTrace) { this.place = place; this.stackTrace = stackTrace; this.reason = reason; this.date = new Date(); this.deviceInfo = DeviceInfoProvider.getDeviceInfo();
if (Sherlock.isInitialized()) {
ajitsing/Sherlock
sherlock/src/main/java/com/singhajit/sherlock/core/database/SherlockDatabaseHelper.java
// Path: sherlock-no-op/src/main/java/com/singhajit/sherlock/core/investigation/Crash.java // public class Crash { // public static final String DATE_FORMAT = "EEE MMM dd kk:mm:ss z yyyy"; // // public Crash(String place, String reason, String stackTrace) { // } // // public Crash(int id, String placeOfCrash, String reasonOfCrash, String stacktrace, String date) { // } // // public DeviceInfo getDeviceInfo() { // return new DeviceInfo.Builder().build(); // } // // public AppInfo getAppInfo() { // return new AppInfo(); // } // // public void setId(int id) { // } // // public Class<Crash> getType() { // return Crash.class; // } // // public String getReason() { // return ""; // } // // public String getStackTrace() { // return ""; // } // // public String getPlace() { // return ""; // } // // public int getId() { // return 0; // } // // public Date getDate() { // return new Date(); // } // }
import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.support.annotation.NonNull; import com.singhajit.sherlock.core.investigation.Crash; import java.util.ArrayList; import java.util.List;
package com.singhajit.sherlock.core.database; public class SherlockDatabaseHelper extends SQLiteOpenHelper { private static final int VERSION = 2; private static final String DB_NAME = "Sherlock"; public SherlockDatabaseHelper(Context context) { super(context, DB_NAME, null, VERSION); } @Override public void onCreate(SQLiteDatabase database) { database.execSQL(CrashTable.CREATE_QUERY); } @Override public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) { sqLiteDatabase.execSQL(CrashTable.DROP_QUERY); sqLiteDatabase.execSQL(CrashTable.CREATE_QUERY); } public int insertCrash(CrashRecord crashRecord) { ContentValues values = new ContentValues(); values.put(CrashTable.PLACE, crashRecord.getPlace()); values.put(CrashTable.REASON, crashRecord.getReason()); values.put(CrashTable.STACKTRACE, crashRecord.getStackTrace()); values.put(CrashTable.DATE, crashRecord.getDate()); SQLiteDatabase database = getWritableDatabase(); long id = database.insert(CrashTable.TABLE_NAME, null, values); database.close(); return Long.valueOf(id).intValue(); }
// Path: sherlock-no-op/src/main/java/com/singhajit/sherlock/core/investigation/Crash.java // public class Crash { // public static final String DATE_FORMAT = "EEE MMM dd kk:mm:ss z yyyy"; // // public Crash(String place, String reason, String stackTrace) { // } // // public Crash(int id, String placeOfCrash, String reasonOfCrash, String stacktrace, String date) { // } // // public DeviceInfo getDeviceInfo() { // return new DeviceInfo.Builder().build(); // } // // public AppInfo getAppInfo() { // return new AppInfo(); // } // // public void setId(int id) { // } // // public Class<Crash> getType() { // return Crash.class; // } // // public String getReason() { // return ""; // } // // public String getStackTrace() { // return ""; // } // // public String getPlace() { // return ""; // } // // public int getId() { // return 0; // } // // public Date getDate() { // return new Date(); // } // } // Path: sherlock/src/main/java/com/singhajit/sherlock/core/database/SherlockDatabaseHelper.java import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.support.annotation.NonNull; import com.singhajit.sherlock.core.investigation.Crash; import java.util.ArrayList; import java.util.List; package com.singhajit.sherlock.core.database; public class SherlockDatabaseHelper extends SQLiteOpenHelper { private static final int VERSION = 2; private static final String DB_NAME = "Sherlock"; public SherlockDatabaseHelper(Context context) { super(context, DB_NAME, null, VERSION); } @Override public void onCreate(SQLiteDatabase database) { database.execSQL(CrashTable.CREATE_QUERY); } @Override public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) { sqLiteDatabase.execSQL(CrashTable.DROP_QUERY); sqLiteDatabase.execSQL(CrashTable.CREATE_QUERY); } public int insertCrash(CrashRecord crashRecord) { ContentValues values = new ContentValues(); values.put(CrashTable.PLACE, crashRecord.getPlace()); values.put(CrashTable.REASON, crashRecord.getReason()); values.put(CrashTable.STACKTRACE, crashRecord.getStackTrace()); values.put(CrashTable.DATE, crashRecord.getDate()); SQLiteDatabase database = getWritableDatabase(); long id = database.insert(CrashTable.TABLE_NAME, null, values); database.close(); return Long.valueOf(id).intValue(); }
public List<Crash> getCrashes() {
ajitsing/Sherlock
sherlock/src/androidTest/java/com/singhajit/sherlock/core/database/SherlockDatabaseHelperTest.java
// Path: sherlock-no-op/src/main/java/com/singhajit/sherlock/core/investigation/Crash.java // public class Crash { // public static final String DATE_FORMAT = "EEE MMM dd kk:mm:ss z yyyy"; // // public Crash(String place, String reason, String stackTrace) { // } // // public Crash(int id, String placeOfCrash, String reasonOfCrash, String stacktrace, String date) { // } // // public DeviceInfo getDeviceInfo() { // return new DeviceInfo.Builder().build(); // } // // public AppInfo getAppInfo() { // return new AppInfo(); // } // // public void setId(int id) { // } // // public Class<Crash> getType() { // return Crash.class; // } // // public String getReason() { // return ""; // } // // public String getStackTrace() { // return ""; // } // // public String getPlace() { // return ""; // } // // public int getId() { // return 0; // } // // public Date getDate() { // return new Date(); // } // }
import android.content.Context; import android.support.test.InstrumentationRegistry; import com.singhajit.sherlock.core.investigation.Crash; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat;
package com.singhajit.sherlock.core.database; public class SherlockDatabaseHelperTest { private SherlockDatabaseHelper database; @Rule public DatabaseResetRule resetRule = new DatabaseResetRule(); @Before public void setUp() throws Exception { Context targetContext = InstrumentationRegistry.getTargetContext(); database = new SherlockDatabaseHelper(targetContext); } @Test public void shouldGetAllCrashes() throws Exception {
// Path: sherlock-no-op/src/main/java/com/singhajit/sherlock/core/investigation/Crash.java // public class Crash { // public static final String DATE_FORMAT = "EEE MMM dd kk:mm:ss z yyyy"; // // public Crash(String place, String reason, String stackTrace) { // } // // public Crash(int id, String placeOfCrash, String reasonOfCrash, String stacktrace, String date) { // } // // public DeviceInfo getDeviceInfo() { // return new DeviceInfo.Builder().build(); // } // // public AppInfo getAppInfo() { // return new AppInfo(); // } // // public void setId(int id) { // } // // public Class<Crash> getType() { // return Crash.class; // } // // public String getReason() { // return ""; // } // // public String getStackTrace() { // return ""; // } // // public String getPlace() { // return ""; // } // // public int getId() { // return 0; // } // // public Date getDate() { // return new Date(); // } // } // Path: sherlock/src/androidTest/java/com/singhajit/sherlock/core/database/SherlockDatabaseHelperTest.java import android.content.Context; import android.support.test.InstrumentationRegistry; import com.singhajit.sherlock.core.investigation.Crash; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; package com.singhajit.sherlock.core.database; public class SherlockDatabaseHelperTest { private SherlockDatabaseHelper database; @Rule public DatabaseResetRule resetRule = new DatabaseResetRule(); @Before public void setUp() throws Exception { Context targetContext = InstrumentationRegistry.getTargetContext(); database = new SherlockDatabaseHelper(targetContext); } @Test public void shouldGetAllCrashes() throws Exception {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Crash.DATE_FORMAT);
ajitsing/Sherlock
sherlock/src/main/java/com/singhajit/sherlock/crashes/action/CrashActions.java
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/CrashViewModel.java // public class CrashViewModel { // private Crash crash; // private AppInfoViewModel appInfoViewModel; // // public CrashViewModel() { // } // // public CrashViewModel(Crash crash) { // populate(crash); // } // // public String getPlace() { // String[] placeTrail = crash.getPlace().split("\\."); // return placeTrail[placeTrail.length - 1]; // } // // public String getExactLocationOfCrash() { // return crash.getPlace(); // } // // public String getReasonOfCrash() { // return crash.getReason(); // } // // public String getStackTrace() { // return crash.getStackTrace(); // } // // public String getCrashInfo() { // StringBuilder crashInfo = new StringBuilder(); // crashInfo.append("Device Info:\n"); // // crashInfo.append("Name: "); // crashInfo.append(getDeviceName() + "\n"); // // crashInfo.append("Brand: "); // crashInfo.append(getDeviceBrand() + "\n"); // // crashInfo.append("Android API: "); // crashInfo.append(getDeviceAndroidApiVersion() + "\n\n"); // // crashInfo.append("App Info:\n"); // crashInfo.append(getAppInfoViewModel().getDetails()); // crashInfo.append("\n"); // // crashInfo.append("StackTrace:\n"); // crashInfo.append(getStackTrace() + "\n"); // // return crashInfo.toString(); // } // // public String getDeviceManufacturer() { // return crash.getDeviceInfo().getManufacturer(); // } // // public String getDeviceName() { // return crash.getDeviceInfo().getName(); // } // // public String getDeviceAndroidApiVersion() { // return crash.getDeviceInfo().getSdk(); // } // // public String getDeviceBrand() { // return crash.getDeviceInfo().getBrand(); // } // // public AppInfoViewModel getAppInfoViewModel() { // return appInfoViewModel; // } // // public int getIdentifier() { // return crash.getId(); // } // // public String getDate() { // SimpleDateFormat simpleDateFormat = new SimpleDateFormat("h:mm a EEE, MMM d, yyyy"); // return simpleDateFormat.format(crash.getDate()); // } // // public void populate(Crash crash) { // this.crash = crash; // this.appInfoViewModel = new AppInfoViewModel(crash.getAppInfo()); // } // } // // Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/viewmodel/AppInfoViewModel.java // public class AppInfoViewModel { // private ArrayList<AppInfoRowViewModel> appInfoRowViewModels; // // public AppInfoViewModel(AppInfo appInfo) { // Map<String, String> appDetails = appInfo.getAppDetails(); // appInfoRowViewModels = toAppInfoRowViewModels(appDetails); // } // // private ArrayList<AppInfoRowViewModel> toAppInfoRowViewModels(Map<String, String> appDetails) { // ArrayList<AppInfoRowViewModel> viewModels = new ArrayList<>(); // for (String key : appDetails.keySet()) { // viewModels.add(new AppInfoRowViewModel(key, appDetails.get(key))); // } // return viewModels; // } // // public String getDetails() { // StringBuilder builder = new StringBuilder(); // for (AppInfoRowViewModel appInfoRowViewModel : appInfoRowViewModels) { // builder.append(appInfoRowViewModel.getAttr() + ": " + appInfoRowViewModel.getVal() + "\n"); // } // // return builder.toString(); // } // // public List<AppInfoRowViewModel> getAppInfoRowViewModels() { // return appInfoRowViewModels; // } // }
import com.singhajit.sherlock.core.investigation.CrashViewModel; import com.singhajit.sherlock.crashes.viewmodel.AppInfoViewModel;
package com.singhajit.sherlock.crashes.action; public interface CrashActions { void openSendApplicationChooser(String crashDetails);
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/CrashViewModel.java // public class CrashViewModel { // private Crash crash; // private AppInfoViewModel appInfoViewModel; // // public CrashViewModel() { // } // // public CrashViewModel(Crash crash) { // populate(crash); // } // // public String getPlace() { // String[] placeTrail = crash.getPlace().split("\\."); // return placeTrail[placeTrail.length - 1]; // } // // public String getExactLocationOfCrash() { // return crash.getPlace(); // } // // public String getReasonOfCrash() { // return crash.getReason(); // } // // public String getStackTrace() { // return crash.getStackTrace(); // } // // public String getCrashInfo() { // StringBuilder crashInfo = new StringBuilder(); // crashInfo.append("Device Info:\n"); // // crashInfo.append("Name: "); // crashInfo.append(getDeviceName() + "\n"); // // crashInfo.append("Brand: "); // crashInfo.append(getDeviceBrand() + "\n"); // // crashInfo.append("Android API: "); // crashInfo.append(getDeviceAndroidApiVersion() + "\n\n"); // // crashInfo.append("App Info:\n"); // crashInfo.append(getAppInfoViewModel().getDetails()); // crashInfo.append("\n"); // // crashInfo.append("StackTrace:\n"); // crashInfo.append(getStackTrace() + "\n"); // // return crashInfo.toString(); // } // // public String getDeviceManufacturer() { // return crash.getDeviceInfo().getManufacturer(); // } // // public String getDeviceName() { // return crash.getDeviceInfo().getName(); // } // // public String getDeviceAndroidApiVersion() { // return crash.getDeviceInfo().getSdk(); // } // // public String getDeviceBrand() { // return crash.getDeviceInfo().getBrand(); // } // // public AppInfoViewModel getAppInfoViewModel() { // return appInfoViewModel; // } // // public int getIdentifier() { // return crash.getId(); // } // // public String getDate() { // SimpleDateFormat simpleDateFormat = new SimpleDateFormat("h:mm a EEE, MMM d, yyyy"); // return simpleDateFormat.format(crash.getDate()); // } // // public void populate(Crash crash) { // this.crash = crash; // this.appInfoViewModel = new AppInfoViewModel(crash.getAppInfo()); // } // } // // Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/viewmodel/AppInfoViewModel.java // public class AppInfoViewModel { // private ArrayList<AppInfoRowViewModel> appInfoRowViewModels; // // public AppInfoViewModel(AppInfo appInfo) { // Map<String, String> appDetails = appInfo.getAppDetails(); // appInfoRowViewModels = toAppInfoRowViewModels(appDetails); // } // // private ArrayList<AppInfoRowViewModel> toAppInfoRowViewModels(Map<String, String> appDetails) { // ArrayList<AppInfoRowViewModel> viewModels = new ArrayList<>(); // for (String key : appDetails.keySet()) { // viewModels.add(new AppInfoRowViewModel(key, appDetails.get(key))); // } // return viewModels; // } // // public String getDetails() { // StringBuilder builder = new StringBuilder(); // for (AppInfoRowViewModel appInfoRowViewModel : appInfoRowViewModels) { // builder.append(appInfoRowViewModel.getAttr() + ": " + appInfoRowViewModel.getVal() + "\n"); // } // // return builder.toString(); // } // // public List<AppInfoRowViewModel> getAppInfoRowViewModels() { // return appInfoRowViewModels; // } // } // Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/action/CrashActions.java import com.singhajit.sherlock.core.investigation.CrashViewModel; import com.singhajit.sherlock.crashes.viewmodel.AppInfoViewModel; package com.singhajit.sherlock.crashes.action; public interface CrashActions { void openSendApplicationChooser(String crashDetails);
void renderAppInfo(AppInfoViewModel viewModel);
ajitsing/Sherlock
sherlock/src/main/java/com/singhajit/sherlock/crashes/action/CrashActions.java
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/CrashViewModel.java // public class CrashViewModel { // private Crash crash; // private AppInfoViewModel appInfoViewModel; // // public CrashViewModel() { // } // // public CrashViewModel(Crash crash) { // populate(crash); // } // // public String getPlace() { // String[] placeTrail = crash.getPlace().split("\\."); // return placeTrail[placeTrail.length - 1]; // } // // public String getExactLocationOfCrash() { // return crash.getPlace(); // } // // public String getReasonOfCrash() { // return crash.getReason(); // } // // public String getStackTrace() { // return crash.getStackTrace(); // } // // public String getCrashInfo() { // StringBuilder crashInfo = new StringBuilder(); // crashInfo.append("Device Info:\n"); // // crashInfo.append("Name: "); // crashInfo.append(getDeviceName() + "\n"); // // crashInfo.append("Brand: "); // crashInfo.append(getDeviceBrand() + "\n"); // // crashInfo.append("Android API: "); // crashInfo.append(getDeviceAndroidApiVersion() + "\n\n"); // // crashInfo.append("App Info:\n"); // crashInfo.append(getAppInfoViewModel().getDetails()); // crashInfo.append("\n"); // // crashInfo.append("StackTrace:\n"); // crashInfo.append(getStackTrace() + "\n"); // // return crashInfo.toString(); // } // // public String getDeviceManufacturer() { // return crash.getDeviceInfo().getManufacturer(); // } // // public String getDeviceName() { // return crash.getDeviceInfo().getName(); // } // // public String getDeviceAndroidApiVersion() { // return crash.getDeviceInfo().getSdk(); // } // // public String getDeviceBrand() { // return crash.getDeviceInfo().getBrand(); // } // // public AppInfoViewModel getAppInfoViewModel() { // return appInfoViewModel; // } // // public int getIdentifier() { // return crash.getId(); // } // // public String getDate() { // SimpleDateFormat simpleDateFormat = new SimpleDateFormat("h:mm a EEE, MMM d, yyyy"); // return simpleDateFormat.format(crash.getDate()); // } // // public void populate(Crash crash) { // this.crash = crash; // this.appInfoViewModel = new AppInfoViewModel(crash.getAppInfo()); // } // } // // Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/viewmodel/AppInfoViewModel.java // public class AppInfoViewModel { // private ArrayList<AppInfoRowViewModel> appInfoRowViewModels; // // public AppInfoViewModel(AppInfo appInfo) { // Map<String, String> appDetails = appInfo.getAppDetails(); // appInfoRowViewModels = toAppInfoRowViewModels(appDetails); // } // // private ArrayList<AppInfoRowViewModel> toAppInfoRowViewModels(Map<String, String> appDetails) { // ArrayList<AppInfoRowViewModel> viewModels = new ArrayList<>(); // for (String key : appDetails.keySet()) { // viewModels.add(new AppInfoRowViewModel(key, appDetails.get(key))); // } // return viewModels; // } // // public String getDetails() { // StringBuilder builder = new StringBuilder(); // for (AppInfoRowViewModel appInfoRowViewModel : appInfoRowViewModels) { // builder.append(appInfoRowViewModel.getAttr() + ": " + appInfoRowViewModel.getVal() + "\n"); // } // // return builder.toString(); // } // // public List<AppInfoRowViewModel> getAppInfoRowViewModels() { // return appInfoRowViewModels; // } // }
import com.singhajit.sherlock.core.investigation.CrashViewModel; import com.singhajit.sherlock.crashes.viewmodel.AppInfoViewModel;
package com.singhajit.sherlock.crashes.action; public interface CrashActions { void openSendApplicationChooser(String crashDetails); void renderAppInfo(AppInfoViewModel viewModel);
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/CrashViewModel.java // public class CrashViewModel { // private Crash crash; // private AppInfoViewModel appInfoViewModel; // // public CrashViewModel() { // } // // public CrashViewModel(Crash crash) { // populate(crash); // } // // public String getPlace() { // String[] placeTrail = crash.getPlace().split("\\."); // return placeTrail[placeTrail.length - 1]; // } // // public String getExactLocationOfCrash() { // return crash.getPlace(); // } // // public String getReasonOfCrash() { // return crash.getReason(); // } // // public String getStackTrace() { // return crash.getStackTrace(); // } // // public String getCrashInfo() { // StringBuilder crashInfo = new StringBuilder(); // crashInfo.append("Device Info:\n"); // // crashInfo.append("Name: "); // crashInfo.append(getDeviceName() + "\n"); // // crashInfo.append("Brand: "); // crashInfo.append(getDeviceBrand() + "\n"); // // crashInfo.append("Android API: "); // crashInfo.append(getDeviceAndroidApiVersion() + "\n\n"); // // crashInfo.append("App Info:\n"); // crashInfo.append(getAppInfoViewModel().getDetails()); // crashInfo.append("\n"); // // crashInfo.append("StackTrace:\n"); // crashInfo.append(getStackTrace() + "\n"); // // return crashInfo.toString(); // } // // public String getDeviceManufacturer() { // return crash.getDeviceInfo().getManufacturer(); // } // // public String getDeviceName() { // return crash.getDeviceInfo().getName(); // } // // public String getDeviceAndroidApiVersion() { // return crash.getDeviceInfo().getSdk(); // } // // public String getDeviceBrand() { // return crash.getDeviceInfo().getBrand(); // } // // public AppInfoViewModel getAppInfoViewModel() { // return appInfoViewModel; // } // // public int getIdentifier() { // return crash.getId(); // } // // public String getDate() { // SimpleDateFormat simpleDateFormat = new SimpleDateFormat("h:mm a EEE, MMM d, yyyy"); // return simpleDateFormat.format(crash.getDate()); // } // // public void populate(Crash crash) { // this.crash = crash; // this.appInfoViewModel = new AppInfoViewModel(crash.getAppInfo()); // } // } // // Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/viewmodel/AppInfoViewModel.java // public class AppInfoViewModel { // private ArrayList<AppInfoRowViewModel> appInfoRowViewModels; // // public AppInfoViewModel(AppInfo appInfo) { // Map<String, String> appDetails = appInfo.getAppDetails(); // appInfoRowViewModels = toAppInfoRowViewModels(appDetails); // } // // private ArrayList<AppInfoRowViewModel> toAppInfoRowViewModels(Map<String, String> appDetails) { // ArrayList<AppInfoRowViewModel> viewModels = new ArrayList<>(); // for (String key : appDetails.keySet()) { // viewModels.add(new AppInfoRowViewModel(key, appDetails.get(key))); // } // return viewModels; // } // // public String getDetails() { // StringBuilder builder = new StringBuilder(); // for (AppInfoRowViewModel appInfoRowViewModel : appInfoRowViewModels) { // builder.append(appInfoRowViewModel.getAttr() + ": " + appInfoRowViewModel.getVal() + "\n"); // } // // return builder.toString(); // } // // public List<AppInfoRowViewModel> getAppInfoRowViewModels() { // return appInfoRowViewModels; // } // } // Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/action/CrashActions.java import com.singhajit.sherlock.core.investigation.CrashViewModel; import com.singhajit.sherlock.crashes.viewmodel.AppInfoViewModel; package com.singhajit.sherlock.crashes.action; public interface CrashActions { void openSendApplicationChooser(String crashDetails); void renderAppInfo(AppInfoViewModel viewModel);
void render(CrashViewModel viewModel);
ajitsing/Sherlock
sherlock/src/main/java/com/singhajit/sherlock/crashes/adapter/AppInfoAdapter.java
// Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/viewmodel/AppInfoRowViewModel.java // public class AppInfoRowViewModel { // private final String attr; // private final String val; // // public AppInfoRowViewModel(String attr, String val) { // this.attr = attr; // this.val = val; // } // // public String getAttr() { // return attr; // } // // public String getVal() { // return val; // } // } // // Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/viewmodel/AppInfoViewModel.java // public class AppInfoViewModel { // private ArrayList<AppInfoRowViewModel> appInfoRowViewModels; // // public AppInfoViewModel(AppInfo appInfo) { // Map<String, String> appDetails = appInfo.getAppDetails(); // appInfoRowViewModels = toAppInfoRowViewModels(appDetails); // } // // private ArrayList<AppInfoRowViewModel> toAppInfoRowViewModels(Map<String, String> appDetails) { // ArrayList<AppInfoRowViewModel> viewModels = new ArrayList<>(); // for (String key : appDetails.keySet()) { // viewModels.add(new AppInfoRowViewModel(key, appDetails.get(key))); // } // return viewModels; // } // // public String getDetails() { // StringBuilder builder = new StringBuilder(); // for (AppInfoRowViewModel appInfoRowViewModel : appInfoRowViewModels) { // builder.append(appInfoRowViewModel.getAttr() + ": " + appInfoRowViewModel.getVal() + "\n"); // } // // return builder.toString(); // } // // public List<AppInfoRowViewModel> getAppInfoRowViewModels() { // return appInfoRowViewModels; // } // }
import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView; import com.singhajit.sherlock.R; import com.singhajit.sherlock.crashes.viewmodel.AppInfoRowViewModel; import com.singhajit.sherlock.crashes.viewmodel.AppInfoViewModel; import java.util.List;
package com.singhajit.sherlock.crashes.adapter; public class AppInfoAdapter extends RecyclerView.Adapter<AppInfoViewHolder> { private final List<AppInfoRowViewModel> appInfoViewModels;
// Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/viewmodel/AppInfoRowViewModel.java // public class AppInfoRowViewModel { // private final String attr; // private final String val; // // public AppInfoRowViewModel(String attr, String val) { // this.attr = attr; // this.val = val; // } // // public String getAttr() { // return attr; // } // // public String getVal() { // return val; // } // } // // Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/viewmodel/AppInfoViewModel.java // public class AppInfoViewModel { // private ArrayList<AppInfoRowViewModel> appInfoRowViewModels; // // public AppInfoViewModel(AppInfo appInfo) { // Map<String, String> appDetails = appInfo.getAppDetails(); // appInfoRowViewModels = toAppInfoRowViewModels(appDetails); // } // // private ArrayList<AppInfoRowViewModel> toAppInfoRowViewModels(Map<String, String> appDetails) { // ArrayList<AppInfoRowViewModel> viewModels = new ArrayList<>(); // for (String key : appDetails.keySet()) { // viewModels.add(new AppInfoRowViewModel(key, appDetails.get(key))); // } // return viewModels; // } // // public String getDetails() { // StringBuilder builder = new StringBuilder(); // for (AppInfoRowViewModel appInfoRowViewModel : appInfoRowViewModels) { // builder.append(appInfoRowViewModel.getAttr() + ": " + appInfoRowViewModel.getVal() + "\n"); // } // // return builder.toString(); // } // // public List<AppInfoRowViewModel> getAppInfoRowViewModels() { // return appInfoRowViewModels; // } // } // Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/adapter/AppInfoAdapter.java import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView; import com.singhajit.sherlock.R; import com.singhajit.sherlock.crashes.viewmodel.AppInfoRowViewModel; import com.singhajit.sherlock.crashes.viewmodel.AppInfoViewModel; import java.util.List; package com.singhajit.sherlock.crashes.adapter; public class AppInfoAdapter extends RecyclerView.Adapter<AppInfoViewHolder> { private final List<AppInfoRowViewModel> appInfoViewModels;
public AppInfoAdapter(AppInfoViewModel appInfoViewModel) {
ajitsing/Sherlock
sherlock/src/main/java/com/singhajit/sherlock/core/investigation/CrashReporter.java
// Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/activity/CrashActivity.java // public class CrashActivity extends BaseActivity implements CrashActions { // public static final String CRASH_ID = "com.singhajit.sherlock.CRASH_ID"; // private CrashViewModel viewModel = new CrashViewModel(); // private CrashPresenter presenter; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // Intent intent = getIntent(); // int crashId = intent.getIntExtra(CRASH_ID, -1); // setContentView(R.layout.crash_activity); // // enableHomeButton((Toolbar) findViewById(R.id.toolbar)); // setTitle(R.string.crash_report); // // presenter = new CrashPresenter(new SherlockDatabaseHelper(this), this); // presenter.render(crashId); // } // // @Override // public boolean onCreateOptionsMenu(Menu menu) { // getMenuInflater().inflate(R.menu.crash_menu, menu); // return true; // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // if (item.getItemId() == R.id.share) { // presenter.shareCrashDetails(viewModel); // return true; // } // return super.onOptionsItemSelected(item); // } // // @Override // public void render(CrashViewModel viewModel) { // this.viewModel = viewModel; // TextView crashLocation = (TextView) findViewById(R.id.crash_location); // TextView crashReason = (TextView) findViewById(R.id.crash_reason); // TextView stackTrace = (TextView) findViewById(R.id.stacktrace); // // crashLocation.setText(viewModel.getExactLocationOfCrash()); // crashReason.setText(viewModel.getReasonOfCrash()); // stackTrace.setText(viewModel.getStackTrace()); // // renderDeviceInfo(viewModel); // } // // @Override // public void openSendApplicationChooser(String crashDetails) { // Intent share = new Intent(Intent.ACTION_SEND); // share.setType("text/plain"); // share.putExtra(Intent.EXTRA_TEXT, crashDetails); // // startActivity(Intent.createChooser(share, getString(R.string.share_dialog_message))); // } // // @Override // public void renderAppInfo(AppInfoViewModel viewModel) { // RecyclerView appInfoDetails = (RecyclerView) findViewById(R.id.app_info_details); // appInfoDetails.setAdapter(new AppInfoAdapter(viewModel)); // appInfoDetails.setLayoutManager(new LinearLayoutManager(this)); // } // // private void renderDeviceInfo(CrashViewModel viewModel) { // TextView deviceName = (TextView) findViewById(R.id.device_name); // TextView deviceBrand = (TextView) findViewById(R.id.device_brand); // TextView deviceAndroidVersion = (TextView) findViewById(R.id.device_android_version); // // deviceName.setText(viewModel.getDeviceName()); // deviceBrand.setText(viewModel.getDeviceBrand()); // deviceAndroidVersion.setText(viewModel.getDeviceAndroidApiVersion()); // } // }
import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.Build; import android.support.v4.app.TaskStackBuilder; import android.support.v4.content.ContextCompat; import com.singhajit.sherlock.R; import com.singhajit.sherlock.crashes.activity.CrashActivity; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
package com.singhajit.sherlock.core.investigation; public class CrashReporter { private final Context context; private String CHANNEL_ID = "com.singhajit.com.221B"; public CrashReporter(Context context) { this.context = context; } public void report(CrashViewModel crashViewModel) { Notification notification = notification(crashViewModel); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( CHANNEL_ID, "Sherlock", IMPORTANCE_DEFAULT ); notificationManager.createNotificationChannel(channel); } notificationManager.notify(crashViewModel.getIdentifier(), notification); } private Notification notification(CrashViewModel crashViewModel) {
// Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/activity/CrashActivity.java // public class CrashActivity extends BaseActivity implements CrashActions { // public static final String CRASH_ID = "com.singhajit.sherlock.CRASH_ID"; // private CrashViewModel viewModel = new CrashViewModel(); // private CrashPresenter presenter; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // Intent intent = getIntent(); // int crashId = intent.getIntExtra(CRASH_ID, -1); // setContentView(R.layout.crash_activity); // // enableHomeButton((Toolbar) findViewById(R.id.toolbar)); // setTitle(R.string.crash_report); // // presenter = new CrashPresenter(new SherlockDatabaseHelper(this), this); // presenter.render(crashId); // } // // @Override // public boolean onCreateOptionsMenu(Menu menu) { // getMenuInflater().inflate(R.menu.crash_menu, menu); // return true; // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // if (item.getItemId() == R.id.share) { // presenter.shareCrashDetails(viewModel); // return true; // } // return super.onOptionsItemSelected(item); // } // // @Override // public void render(CrashViewModel viewModel) { // this.viewModel = viewModel; // TextView crashLocation = (TextView) findViewById(R.id.crash_location); // TextView crashReason = (TextView) findViewById(R.id.crash_reason); // TextView stackTrace = (TextView) findViewById(R.id.stacktrace); // // crashLocation.setText(viewModel.getExactLocationOfCrash()); // crashReason.setText(viewModel.getReasonOfCrash()); // stackTrace.setText(viewModel.getStackTrace()); // // renderDeviceInfo(viewModel); // } // // @Override // public void openSendApplicationChooser(String crashDetails) { // Intent share = new Intent(Intent.ACTION_SEND); // share.setType("text/plain"); // share.putExtra(Intent.EXTRA_TEXT, crashDetails); // // startActivity(Intent.createChooser(share, getString(R.string.share_dialog_message))); // } // // @Override // public void renderAppInfo(AppInfoViewModel viewModel) { // RecyclerView appInfoDetails = (RecyclerView) findViewById(R.id.app_info_details); // appInfoDetails.setAdapter(new AppInfoAdapter(viewModel)); // appInfoDetails.setLayoutManager(new LinearLayoutManager(this)); // } // // private void renderDeviceInfo(CrashViewModel viewModel) { // TextView deviceName = (TextView) findViewById(R.id.device_name); // TextView deviceBrand = (TextView) findViewById(R.id.device_brand); // TextView deviceAndroidVersion = (TextView) findViewById(R.id.device_android_version); // // deviceName.setText(viewModel.getDeviceName()); // deviceBrand.setText(viewModel.getDeviceBrand()); // deviceAndroidVersion.setText(viewModel.getDeviceAndroidApiVersion()); // } // } // Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/CrashReporter.java import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.Build; import android.support.v4.app.TaskStackBuilder; import android.support.v4.content.ContextCompat; import com.singhajit.sherlock.R; import com.singhajit.sherlock.crashes.activity.CrashActivity; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; package com.singhajit.sherlock.core.investigation; public class CrashReporter { private final Context context; private String CHANNEL_ID = "com.singhajit.com.221B"; public CrashReporter(Context context) { this.context = context; } public void report(CrashViewModel crashViewModel) { Notification notification = notification(crashViewModel); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( CHANNEL_ID, "Sherlock", IMPORTANCE_DEFAULT ); notificationManager.createNotificationChannel(channel); } notificationManager.notify(crashViewModel.getIdentifier(), notification); } private Notification notification(CrashViewModel crashViewModel) {
Intent crashActivityIntent = new Intent(context, CrashActivity.class);
ajitsing/Sherlock
sherlock-no-op/src/main/java/com/singhajit/sherlock/core/Sherlock.java
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/AppInfo.java // public class AppInfo { // private List<Pair> appDetails = new ArrayList<>(); // // private AppInfo(List<Pair> appDetails) { // this.appDetails = appDetails; // } // // public Map<String, String> getAppDetails() { // TreeMap<String, String> details = new TreeMap<>(); // for (Pair pair : appDetails) { // details.put(pair.getKey(), pair.getVal()); // } // return details.descendingMap(); // } // // public static class Builder { // List<Pair> appDetails = new ArrayList<>(); // // public Builder with(String key, String value) { // appDetails.add(new Pair(key, value)); // return this; // } // // public AppInfo build() { // return new AppInfo(appDetails); // } // } // } // // Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/AppInfoProvider.java // public interface AppInfoProvider { // AppInfo getAppInfo(); // } // // Path: sherlock-no-op/src/main/java/com/singhajit/sherlock/core/investigation/Crash.java // public class Crash { // public static final String DATE_FORMAT = "EEE MMM dd kk:mm:ss z yyyy"; // // public Crash(String place, String reason, String stackTrace) { // } // // public Crash(int id, String placeOfCrash, String reasonOfCrash, String stacktrace, String date) { // } // // public DeviceInfo getDeviceInfo() { // return new DeviceInfo.Builder().build(); // } // // public AppInfo getAppInfo() { // return new AppInfo(); // } // // public void setId(int id) { // } // // public Class<Crash> getType() { // return Crash.class; // } // // public String getReason() { // return ""; // } // // public String getStackTrace() { // return ""; // } // // public String getPlace() { // return ""; // } // // public int getId() { // return 0; // } // // public Date getDate() { // return new Date(); // } // }
import android.content.Context; import com.singhajit.sherlock.core.investigation.AppInfo; import com.singhajit.sherlock.core.investigation.AppInfoProvider; import com.singhajit.sherlock.core.investigation.Crash; import java.util.ArrayList; import java.util.List;
package com.singhajit.sherlock.core; public class Sherlock { public static void init(final Context context) { } public static boolean isInitialized() { return false; } public static Sherlock getInstance() { return new Sherlock(); }
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/AppInfo.java // public class AppInfo { // private List<Pair> appDetails = new ArrayList<>(); // // private AppInfo(List<Pair> appDetails) { // this.appDetails = appDetails; // } // // public Map<String, String> getAppDetails() { // TreeMap<String, String> details = new TreeMap<>(); // for (Pair pair : appDetails) { // details.put(pair.getKey(), pair.getVal()); // } // return details.descendingMap(); // } // // public static class Builder { // List<Pair> appDetails = new ArrayList<>(); // // public Builder with(String key, String value) { // appDetails.add(new Pair(key, value)); // return this; // } // // public AppInfo build() { // return new AppInfo(appDetails); // } // } // } // // Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/AppInfoProvider.java // public interface AppInfoProvider { // AppInfo getAppInfo(); // } // // Path: sherlock-no-op/src/main/java/com/singhajit/sherlock/core/investigation/Crash.java // public class Crash { // public static final String DATE_FORMAT = "EEE MMM dd kk:mm:ss z yyyy"; // // public Crash(String place, String reason, String stackTrace) { // } // // public Crash(int id, String placeOfCrash, String reasonOfCrash, String stacktrace, String date) { // } // // public DeviceInfo getDeviceInfo() { // return new DeviceInfo.Builder().build(); // } // // public AppInfo getAppInfo() { // return new AppInfo(); // } // // public void setId(int id) { // } // // public Class<Crash> getType() { // return Crash.class; // } // // public String getReason() { // return ""; // } // // public String getStackTrace() { // return ""; // } // // public String getPlace() { // return ""; // } // // public int getId() { // return 0; // } // // public Date getDate() { // return new Date(); // } // } // Path: sherlock-no-op/src/main/java/com/singhajit/sherlock/core/Sherlock.java import android.content.Context; import com.singhajit.sherlock.core.investigation.AppInfo; import com.singhajit.sherlock.core.investigation.AppInfoProvider; import com.singhajit.sherlock.core.investigation.Crash; import java.util.ArrayList; import java.util.List; package com.singhajit.sherlock.core; public class Sherlock { public static void init(final Context context) { } public static boolean isInitialized() { return false; } public static Sherlock getInstance() { return new Sherlock(); }
public List<Crash> getAllCrashes() {
ajitsing/Sherlock
sherlock-no-op/src/main/java/com/singhajit/sherlock/core/Sherlock.java
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/AppInfo.java // public class AppInfo { // private List<Pair> appDetails = new ArrayList<>(); // // private AppInfo(List<Pair> appDetails) { // this.appDetails = appDetails; // } // // public Map<String, String> getAppDetails() { // TreeMap<String, String> details = new TreeMap<>(); // for (Pair pair : appDetails) { // details.put(pair.getKey(), pair.getVal()); // } // return details.descendingMap(); // } // // public static class Builder { // List<Pair> appDetails = new ArrayList<>(); // // public Builder with(String key, String value) { // appDetails.add(new Pair(key, value)); // return this; // } // // public AppInfo build() { // return new AppInfo(appDetails); // } // } // } // // Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/AppInfoProvider.java // public interface AppInfoProvider { // AppInfo getAppInfo(); // } // // Path: sherlock-no-op/src/main/java/com/singhajit/sherlock/core/investigation/Crash.java // public class Crash { // public static final String DATE_FORMAT = "EEE MMM dd kk:mm:ss z yyyy"; // // public Crash(String place, String reason, String stackTrace) { // } // // public Crash(int id, String placeOfCrash, String reasonOfCrash, String stacktrace, String date) { // } // // public DeviceInfo getDeviceInfo() { // return new DeviceInfo.Builder().build(); // } // // public AppInfo getAppInfo() { // return new AppInfo(); // } // // public void setId(int id) { // } // // public Class<Crash> getType() { // return Crash.class; // } // // public String getReason() { // return ""; // } // // public String getStackTrace() { // return ""; // } // // public String getPlace() { // return ""; // } // // public int getId() { // return 0; // } // // public Date getDate() { // return new Date(); // } // }
import android.content.Context; import com.singhajit.sherlock.core.investigation.AppInfo; import com.singhajit.sherlock.core.investigation.AppInfoProvider; import com.singhajit.sherlock.core.investigation.Crash; import java.util.ArrayList; import java.util.List;
package com.singhajit.sherlock.core; public class Sherlock { public static void init(final Context context) { } public static boolean isInitialized() { return false; } public static Sherlock getInstance() { return new Sherlock(); } public List<Crash> getAllCrashes() { return new ArrayList<>(); }
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/AppInfo.java // public class AppInfo { // private List<Pair> appDetails = new ArrayList<>(); // // private AppInfo(List<Pair> appDetails) { // this.appDetails = appDetails; // } // // public Map<String, String> getAppDetails() { // TreeMap<String, String> details = new TreeMap<>(); // for (Pair pair : appDetails) { // details.put(pair.getKey(), pair.getVal()); // } // return details.descendingMap(); // } // // public static class Builder { // List<Pair> appDetails = new ArrayList<>(); // // public Builder with(String key, String value) { // appDetails.add(new Pair(key, value)); // return this; // } // // public AppInfo build() { // return new AppInfo(appDetails); // } // } // } // // Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/AppInfoProvider.java // public interface AppInfoProvider { // AppInfo getAppInfo(); // } // // Path: sherlock-no-op/src/main/java/com/singhajit/sherlock/core/investigation/Crash.java // public class Crash { // public static final String DATE_FORMAT = "EEE MMM dd kk:mm:ss z yyyy"; // // public Crash(String place, String reason, String stackTrace) { // } // // public Crash(int id, String placeOfCrash, String reasonOfCrash, String stacktrace, String date) { // } // // public DeviceInfo getDeviceInfo() { // return new DeviceInfo.Builder().build(); // } // // public AppInfo getAppInfo() { // return new AppInfo(); // } // // public void setId(int id) { // } // // public Class<Crash> getType() { // return Crash.class; // } // // public String getReason() { // return ""; // } // // public String getStackTrace() { // return ""; // } // // public String getPlace() { // return ""; // } // // public int getId() { // return 0; // } // // public Date getDate() { // return new Date(); // } // } // Path: sherlock-no-op/src/main/java/com/singhajit/sherlock/core/Sherlock.java import android.content.Context; import com.singhajit.sherlock.core.investigation.AppInfo; import com.singhajit.sherlock.core.investigation.AppInfoProvider; import com.singhajit.sherlock.core.investigation.Crash; import java.util.ArrayList; import java.util.List; package com.singhajit.sherlock.core; public class Sherlock { public static void init(final Context context) { } public static boolean isInitialized() { return false; } public static Sherlock getInstance() { return new Sherlock(); } public List<Crash> getAllCrashes() { return new ArrayList<>(); }
public static void setAppInfoProvider(AppInfoProvider appInfoProvider) {
ajitsing/Sherlock
sherlock-no-op/src/main/java/com/singhajit/sherlock/core/Sherlock.java
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/AppInfo.java // public class AppInfo { // private List<Pair> appDetails = new ArrayList<>(); // // private AppInfo(List<Pair> appDetails) { // this.appDetails = appDetails; // } // // public Map<String, String> getAppDetails() { // TreeMap<String, String> details = new TreeMap<>(); // for (Pair pair : appDetails) { // details.put(pair.getKey(), pair.getVal()); // } // return details.descendingMap(); // } // // public static class Builder { // List<Pair> appDetails = new ArrayList<>(); // // public Builder with(String key, String value) { // appDetails.add(new Pair(key, value)); // return this; // } // // public AppInfo build() { // return new AppInfo(appDetails); // } // } // } // // Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/AppInfoProvider.java // public interface AppInfoProvider { // AppInfo getAppInfo(); // } // // Path: sherlock-no-op/src/main/java/com/singhajit/sherlock/core/investigation/Crash.java // public class Crash { // public static final String DATE_FORMAT = "EEE MMM dd kk:mm:ss z yyyy"; // // public Crash(String place, String reason, String stackTrace) { // } // // public Crash(int id, String placeOfCrash, String reasonOfCrash, String stacktrace, String date) { // } // // public DeviceInfo getDeviceInfo() { // return new DeviceInfo.Builder().build(); // } // // public AppInfo getAppInfo() { // return new AppInfo(); // } // // public void setId(int id) { // } // // public Class<Crash> getType() { // return Crash.class; // } // // public String getReason() { // return ""; // } // // public String getStackTrace() { // return ""; // } // // public String getPlace() { // return ""; // } // // public int getId() { // return 0; // } // // public Date getDate() { // return new Date(); // } // }
import android.content.Context; import com.singhajit.sherlock.core.investigation.AppInfo; import com.singhajit.sherlock.core.investigation.AppInfoProvider; import com.singhajit.sherlock.core.investigation.Crash; import java.util.ArrayList; import java.util.List;
package com.singhajit.sherlock.core; public class Sherlock { public static void init(final Context context) { } public static boolean isInitialized() { return false; } public static Sherlock getInstance() { return new Sherlock(); } public List<Crash> getAllCrashes() { return new ArrayList<>(); } public static void setAppInfoProvider(AppInfoProvider appInfoProvider) { } public AppInfoProvider getAppInfoProvider() { return new AppInfoProvider() { @Override
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/AppInfo.java // public class AppInfo { // private List<Pair> appDetails = new ArrayList<>(); // // private AppInfo(List<Pair> appDetails) { // this.appDetails = appDetails; // } // // public Map<String, String> getAppDetails() { // TreeMap<String, String> details = new TreeMap<>(); // for (Pair pair : appDetails) { // details.put(pair.getKey(), pair.getVal()); // } // return details.descendingMap(); // } // // public static class Builder { // List<Pair> appDetails = new ArrayList<>(); // // public Builder with(String key, String value) { // appDetails.add(new Pair(key, value)); // return this; // } // // public AppInfo build() { // return new AppInfo(appDetails); // } // } // } // // Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/AppInfoProvider.java // public interface AppInfoProvider { // AppInfo getAppInfo(); // } // // Path: sherlock-no-op/src/main/java/com/singhajit/sherlock/core/investigation/Crash.java // public class Crash { // public static final String DATE_FORMAT = "EEE MMM dd kk:mm:ss z yyyy"; // // public Crash(String place, String reason, String stackTrace) { // } // // public Crash(int id, String placeOfCrash, String reasonOfCrash, String stacktrace, String date) { // } // // public DeviceInfo getDeviceInfo() { // return new DeviceInfo.Builder().build(); // } // // public AppInfo getAppInfo() { // return new AppInfo(); // } // // public void setId(int id) { // } // // public Class<Crash> getType() { // return Crash.class; // } // // public String getReason() { // return ""; // } // // public String getStackTrace() { // return ""; // } // // public String getPlace() { // return ""; // } // // public int getId() { // return 0; // } // // public Date getDate() { // return new Date(); // } // } // Path: sherlock-no-op/src/main/java/com/singhajit/sherlock/core/Sherlock.java import android.content.Context; import com.singhajit.sherlock.core.investigation.AppInfo; import com.singhajit.sherlock.core.investigation.AppInfoProvider; import com.singhajit.sherlock.core.investigation.Crash; import java.util.ArrayList; import java.util.List; package com.singhajit.sherlock.core; public class Sherlock { public static void init(final Context context) { } public static boolean isInitialized() { return false; } public static Sherlock getInstance() { return new Sherlock(); } public List<Crash> getAllCrashes() { return new ArrayList<>(); } public static void setAppInfoProvider(AppInfoProvider appInfoProvider) { } public AppInfoProvider getAppInfoProvider() { return new AppInfoProvider() { @Override
public AppInfo getAppInfo() {
ajitsing/Sherlock
sherlock/src/main/java/com/singhajit/sherlock/core/investigation/CrashViewModel.java
// Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/viewmodel/AppInfoViewModel.java // public class AppInfoViewModel { // private ArrayList<AppInfoRowViewModel> appInfoRowViewModels; // // public AppInfoViewModel(AppInfo appInfo) { // Map<String, String> appDetails = appInfo.getAppDetails(); // appInfoRowViewModels = toAppInfoRowViewModels(appDetails); // } // // private ArrayList<AppInfoRowViewModel> toAppInfoRowViewModels(Map<String, String> appDetails) { // ArrayList<AppInfoRowViewModel> viewModels = new ArrayList<>(); // for (String key : appDetails.keySet()) { // viewModels.add(new AppInfoRowViewModel(key, appDetails.get(key))); // } // return viewModels; // } // // public String getDetails() { // StringBuilder builder = new StringBuilder(); // for (AppInfoRowViewModel appInfoRowViewModel : appInfoRowViewModels) { // builder.append(appInfoRowViewModel.getAttr() + ": " + appInfoRowViewModel.getVal() + "\n"); // } // // return builder.toString(); // } // // public List<AppInfoRowViewModel> getAppInfoRowViewModels() { // return appInfoRowViewModels; // } // }
import com.singhajit.sherlock.crashes.viewmodel.AppInfoViewModel; import java.text.SimpleDateFormat;
package com.singhajit.sherlock.core.investigation; public class CrashViewModel { private Crash crash;
// Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/viewmodel/AppInfoViewModel.java // public class AppInfoViewModel { // private ArrayList<AppInfoRowViewModel> appInfoRowViewModels; // // public AppInfoViewModel(AppInfo appInfo) { // Map<String, String> appDetails = appInfo.getAppDetails(); // appInfoRowViewModels = toAppInfoRowViewModels(appDetails); // } // // private ArrayList<AppInfoRowViewModel> toAppInfoRowViewModels(Map<String, String> appDetails) { // ArrayList<AppInfoRowViewModel> viewModels = new ArrayList<>(); // for (String key : appDetails.keySet()) { // viewModels.add(new AppInfoRowViewModel(key, appDetails.get(key))); // } // return viewModels; // } // // public String getDetails() { // StringBuilder builder = new StringBuilder(); // for (AppInfoRowViewModel appInfoRowViewModel : appInfoRowViewModels) { // builder.append(appInfoRowViewModel.getAttr() + ": " + appInfoRowViewModel.getVal() + "\n"); // } // // return builder.toString(); // } // // public List<AppInfoRowViewModel> getAppInfoRowViewModels() { // return appInfoRowViewModels; // } // } // Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/CrashViewModel.java import com.singhajit.sherlock.crashes.viewmodel.AppInfoViewModel; import java.text.SimpleDateFormat; package com.singhajit.sherlock.core.investigation; public class CrashViewModel { private Crash crash;
private AppInfoViewModel appInfoViewModel;
ajitsing/Sherlock
sherlock/src/main/java/com/singhajit/sherlock/crashes/adapter/CrashAdapter.java
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/CrashViewModel.java // public class CrashViewModel { // private Crash crash; // private AppInfoViewModel appInfoViewModel; // // public CrashViewModel() { // } // // public CrashViewModel(Crash crash) { // populate(crash); // } // // public String getPlace() { // String[] placeTrail = crash.getPlace().split("\\."); // return placeTrail[placeTrail.length - 1]; // } // // public String getExactLocationOfCrash() { // return crash.getPlace(); // } // // public String getReasonOfCrash() { // return crash.getReason(); // } // // public String getStackTrace() { // return crash.getStackTrace(); // } // // public String getCrashInfo() { // StringBuilder crashInfo = new StringBuilder(); // crashInfo.append("Device Info:\n"); // // crashInfo.append("Name: "); // crashInfo.append(getDeviceName() + "\n"); // // crashInfo.append("Brand: "); // crashInfo.append(getDeviceBrand() + "\n"); // // crashInfo.append("Android API: "); // crashInfo.append(getDeviceAndroidApiVersion() + "\n\n"); // // crashInfo.append("App Info:\n"); // crashInfo.append(getAppInfoViewModel().getDetails()); // crashInfo.append("\n"); // // crashInfo.append("StackTrace:\n"); // crashInfo.append(getStackTrace() + "\n"); // // return crashInfo.toString(); // } // // public String getDeviceManufacturer() { // return crash.getDeviceInfo().getManufacturer(); // } // // public String getDeviceName() { // return crash.getDeviceInfo().getName(); // } // // public String getDeviceAndroidApiVersion() { // return crash.getDeviceInfo().getSdk(); // } // // public String getDeviceBrand() { // return crash.getDeviceInfo().getBrand(); // } // // public AppInfoViewModel getAppInfoViewModel() { // return appInfoViewModel; // } // // public int getIdentifier() { // return crash.getId(); // } // // public String getDate() { // SimpleDateFormat simpleDateFormat = new SimpleDateFormat("h:mm a EEE, MMM d, yyyy"); // return simpleDateFormat.format(crash.getDate()); // } // // public void populate(Crash crash) { // this.crash = crash; // this.appInfoViewModel = new AppInfoViewModel(crash.getAppInfo()); // } // } // // Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/presenter/CrashListPresenter.java // public class CrashListPresenter { // private final CrashListActions actions; // // public CrashListPresenter(CrashListActions actions) { // this.actions = actions; // } // // public void render(SherlockDatabaseHelper database) { // List<Crash> crashes = database.getCrashes(); // ArrayList<CrashViewModel> crashViewModels = new ArrayList<>(); // for (Crash crash : crashes) { // crashViewModels.add(new CrashViewModel(crash)); // } // actions.render(new CrashesViewModel(crashViewModels)); // } // // public void onCrashClicked(CrashViewModel viewModel) { // actions.openCrashDetails(viewModel.getIdentifier()); // } // }
import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView; import com.singhajit.sherlock.R; import com.singhajit.sherlock.core.investigation.CrashViewModel; import com.singhajit.sherlock.crashes.presenter.CrashListPresenter; import java.util.List;
package com.singhajit.sherlock.crashes.adapter; public class CrashAdapter extends RecyclerView.Adapter<CrashViewHolder> { private final List<CrashViewModel> crashes;
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/CrashViewModel.java // public class CrashViewModel { // private Crash crash; // private AppInfoViewModel appInfoViewModel; // // public CrashViewModel() { // } // // public CrashViewModel(Crash crash) { // populate(crash); // } // // public String getPlace() { // String[] placeTrail = crash.getPlace().split("\\."); // return placeTrail[placeTrail.length - 1]; // } // // public String getExactLocationOfCrash() { // return crash.getPlace(); // } // // public String getReasonOfCrash() { // return crash.getReason(); // } // // public String getStackTrace() { // return crash.getStackTrace(); // } // // public String getCrashInfo() { // StringBuilder crashInfo = new StringBuilder(); // crashInfo.append("Device Info:\n"); // // crashInfo.append("Name: "); // crashInfo.append(getDeviceName() + "\n"); // // crashInfo.append("Brand: "); // crashInfo.append(getDeviceBrand() + "\n"); // // crashInfo.append("Android API: "); // crashInfo.append(getDeviceAndroidApiVersion() + "\n\n"); // // crashInfo.append("App Info:\n"); // crashInfo.append(getAppInfoViewModel().getDetails()); // crashInfo.append("\n"); // // crashInfo.append("StackTrace:\n"); // crashInfo.append(getStackTrace() + "\n"); // // return crashInfo.toString(); // } // // public String getDeviceManufacturer() { // return crash.getDeviceInfo().getManufacturer(); // } // // public String getDeviceName() { // return crash.getDeviceInfo().getName(); // } // // public String getDeviceAndroidApiVersion() { // return crash.getDeviceInfo().getSdk(); // } // // public String getDeviceBrand() { // return crash.getDeviceInfo().getBrand(); // } // // public AppInfoViewModel getAppInfoViewModel() { // return appInfoViewModel; // } // // public int getIdentifier() { // return crash.getId(); // } // // public String getDate() { // SimpleDateFormat simpleDateFormat = new SimpleDateFormat("h:mm a EEE, MMM d, yyyy"); // return simpleDateFormat.format(crash.getDate()); // } // // public void populate(Crash crash) { // this.crash = crash; // this.appInfoViewModel = new AppInfoViewModel(crash.getAppInfo()); // } // } // // Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/presenter/CrashListPresenter.java // public class CrashListPresenter { // private final CrashListActions actions; // // public CrashListPresenter(CrashListActions actions) { // this.actions = actions; // } // // public void render(SherlockDatabaseHelper database) { // List<Crash> crashes = database.getCrashes(); // ArrayList<CrashViewModel> crashViewModels = new ArrayList<>(); // for (Crash crash : crashes) { // crashViewModels.add(new CrashViewModel(crash)); // } // actions.render(new CrashesViewModel(crashViewModels)); // } // // public void onCrashClicked(CrashViewModel viewModel) { // actions.openCrashDetails(viewModel.getIdentifier()); // } // } // Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/adapter/CrashAdapter.java import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView; import com.singhajit.sherlock.R; import com.singhajit.sherlock.core.investigation.CrashViewModel; import com.singhajit.sherlock.crashes.presenter.CrashListPresenter; import java.util.List; package com.singhajit.sherlock.crashes.adapter; public class CrashAdapter extends RecyclerView.Adapter<CrashViewHolder> { private final List<CrashViewModel> crashes;
private final CrashListPresenter presenter;
ajitsing/Sherlock
sherlock/src/test/java/com/singhajit/sherlock/crashes/viewmodel/CrashesViewModelTest.java
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/CrashViewModel.java // public class CrashViewModel { // private Crash crash; // private AppInfoViewModel appInfoViewModel; // // public CrashViewModel() { // } // // public CrashViewModel(Crash crash) { // populate(crash); // } // // public String getPlace() { // String[] placeTrail = crash.getPlace().split("\\."); // return placeTrail[placeTrail.length - 1]; // } // // public String getExactLocationOfCrash() { // return crash.getPlace(); // } // // public String getReasonOfCrash() { // return crash.getReason(); // } // // public String getStackTrace() { // return crash.getStackTrace(); // } // // public String getCrashInfo() { // StringBuilder crashInfo = new StringBuilder(); // crashInfo.append("Device Info:\n"); // // crashInfo.append("Name: "); // crashInfo.append(getDeviceName() + "\n"); // // crashInfo.append("Brand: "); // crashInfo.append(getDeviceBrand() + "\n"); // // crashInfo.append("Android API: "); // crashInfo.append(getDeviceAndroidApiVersion() + "\n\n"); // // crashInfo.append("App Info:\n"); // crashInfo.append(getAppInfoViewModel().getDetails()); // crashInfo.append("\n"); // // crashInfo.append("StackTrace:\n"); // crashInfo.append(getStackTrace() + "\n"); // // return crashInfo.toString(); // } // // public String getDeviceManufacturer() { // return crash.getDeviceInfo().getManufacturer(); // } // // public String getDeviceName() { // return crash.getDeviceInfo().getName(); // } // // public String getDeviceAndroidApiVersion() { // return crash.getDeviceInfo().getSdk(); // } // // public String getDeviceBrand() { // return crash.getDeviceInfo().getBrand(); // } // // public AppInfoViewModel getAppInfoViewModel() { // return appInfoViewModel; // } // // public int getIdentifier() { // return crash.getId(); // } // // public String getDate() { // SimpleDateFormat simpleDateFormat = new SimpleDateFormat("h:mm a EEE, MMM d, yyyy"); // return simpleDateFormat.format(crash.getDate()); // } // // public void populate(Crash crash) { // this.crash = crash; // this.appInfoViewModel = new AppInfoViewModel(crash.getAppInfo()); // } // }
import android.view.View; import com.singhajit.sherlock.core.investigation.CrashViewModel; import org.junit.Test; import java.util.ArrayList; import static java.util.Arrays.asList; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.mock;
package com.singhajit.sherlock.crashes.viewmodel; public class CrashesViewModelTest { @Test public void shouldReturnCrashNotFoundVisibilityAsVISBILEWhenThereAreNoCrashes() throws Exception {
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/CrashViewModel.java // public class CrashViewModel { // private Crash crash; // private AppInfoViewModel appInfoViewModel; // // public CrashViewModel() { // } // // public CrashViewModel(Crash crash) { // populate(crash); // } // // public String getPlace() { // String[] placeTrail = crash.getPlace().split("\\."); // return placeTrail[placeTrail.length - 1]; // } // // public String getExactLocationOfCrash() { // return crash.getPlace(); // } // // public String getReasonOfCrash() { // return crash.getReason(); // } // // public String getStackTrace() { // return crash.getStackTrace(); // } // // public String getCrashInfo() { // StringBuilder crashInfo = new StringBuilder(); // crashInfo.append("Device Info:\n"); // // crashInfo.append("Name: "); // crashInfo.append(getDeviceName() + "\n"); // // crashInfo.append("Brand: "); // crashInfo.append(getDeviceBrand() + "\n"); // // crashInfo.append("Android API: "); // crashInfo.append(getDeviceAndroidApiVersion() + "\n\n"); // // crashInfo.append("App Info:\n"); // crashInfo.append(getAppInfoViewModel().getDetails()); // crashInfo.append("\n"); // // crashInfo.append("StackTrace:\n"); // crashInfo.append(getStackTrace() + "\n"); // // return crashInfo.toString(); // } // // public String getDeviceManufacturer() { // return crash.getDeviceInfo().getManufacturer(); // } // // public String getDeviceName() { // return crash.getDeviceInfo().getName(); // } // // public String getDeviceAndroidApiVersion() { // return crash.getDeviceInfo().getSdk(); // } // // public String getDeviceBrand() { // return crash.getDeviceInfo().getBrand(); // } // // public AppInfoViewModel getAppInfoViewModel() { // return appInfoViewModel; // } // // public int getIdentifier() { // return crash.getId(); // } // // public String getDate() { // SimpleDateFormat simpleDateFormat = new SimpleDateFormat("h:mm a EEE, MMM d, yyyy"); // return simpleDateFormat.format(crash.getDate()); // } // // public void populate(Crash crash) { // this.crash = crash; // this.appInfoViewModel = new AppInfoViewModel(crash.getAppInfo()); // } // } // Path: sherlock/src/test/java/com/singhajit/sherlock/crashes/viewmodel/CrashesViewModelTest.java import android.view.View; import com.singhajit.sherlock.core.investigation.CrashViewModel; import org.junit.Test; import java.util.ArrayList; import static java.util.Arrays.asList; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.mock; package com.singhajit.sherlock.crashes.viewmodel; public class CrashesViewModelTest { @Test public void shouldReturnCrashNotFoundVisibilityAsVISBILEWhenThereAreNoCrashes() throws Exception {
CrashesViewModel viewModel = new CrashesViewModel(new ArrayList<CrashViewModel>());
ajitsing/Sherlock
sherlock/src/main/java/com/singhajit/sherlock/core/investigation/DefaultAppInfoProvider.java
// Path: sherlock/src/main/java/com/singhajit/sherlock/util/AppInfoUtil.java // public class AppInfoUtil { // public static String getAppVersion(Context context) { // try { // return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; // } catch (PackageManager.NameNotFoundException e) { // return "Not Found"; // } // } // }
import android.content.Context; import com.singhajit.sherlock.util.AppInfoUtil;
package com.singhajit.sherlock.core.investigation; public class DefaultAppInfoProvider implements AppInfoProvider { private final Context context; public DefaultAppInfoProvider(Context context) { this.context = context; } @Override public AppInfo getAppInfo() { return new AppInfo.Builder()
// Path: sherlock/src/main/java/com/singhajit/sherlock/util/AppInfoUtil.java // public class AppInfoUtil { // public static String getAppVersion(Context context) { // try { // return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; // } catch (PackageManager.NameNotFoundException e) { // return "Not Found"; // } // } // } // Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/DefaultAppInfoProvider.java import android.content.Context; import com.singhajit.sherlock.util.AppInfoUtil; package com.singhajit.sherlock.core.investigation; public class DefaultAppInfoProvider implements AppInfoProvider { private final Context context; public DefaultAppInfoProvider(Context context) { this.context = context; } @Override public AppInfo getAppInfo() { return new AppInfo.Builder()
.with("Version", AppInfoUtil.getAppVersion(context))
ajitsing/Sherlock
sherlock/src/main/java/com/singhajit/sherlock/crashes/viewmodel/CrashesViewModel.java
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/CrashViewModel.java // public class CrashViewModel { // private Crash crash; // private AppInfoViewModel appInfoViewModel; // // public CrashViewModel() { // } // // public CrashViewModel(Crash crash) { // populate(crash); // } // // public String getPlace() { // String[] placeTrail = crash.getPlace().split("\\."); // return placeTrail[placeTrail.length - 1]; // } // // public String getExactLocationOfCrash() { // return crash.getPlace(); // } // // public String getReasonOfCrash() { // return crash.getReason(); // } // // public String getStackTrace() { // return crash.getStackTrace(); // } // // public String getCrashInfo() { // StringBuilder crashInfo = new StringBuilder(); // crashInfo.append("Device Info:\n"); // // crashInfo.append("Name: "); // crashInfo.append(getDeviceName() + "\n"); // // crashInfo.append("Brand: "); // crashInfo.append(getDeviceBrand() + "\n"); // // crashInfo.append("Android API: "); // crashInfo.append(getDeviceAndroidApiVersion() + "\n\n"); // // crashInfo.append("App Info:\n"); // crashInfo.append(getAppInfoViewModel().getDetails()); // crashInfo.append("\n"); // // crashInfo.append("StackTrace:\n"); // crashInfo.append(getStackTrace() + "\n"); // // return crashInfo.toString(); // } // // public String getDeviceManufacturer() { // return crash.getDeviceInfo().getManufacturer(); // } // // public String getDeviceName() { // return crash.getDeviceInfo().getName(); // } // // public String getDeviceAndroidApiVersion() { // return crash.getDeviceInfo().getSdk(); // } // // public String getDeviceBrand() { // return crash.getDeviceInfo().getBrand(); // } // // public AppInfoViewModel getAppInfoViewModel() { // return appInfoViewModel; // } // // public int getIdentifier() { // return crash.getId(); // } // // public String getDate() { // SimpleDateFormat simpleDateFormat = new SimpleDateFormat("h:mm a EEE, MMM d, yyyy"); // return simpleDateFormat.format(crash.getDate()); // } // // public void populate(Crash crash) { // this.crash = crash; // this.appInfoViewModel = new AppInfoViewModel(crash.getAppInfo()); // } // } // // Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/util/ViewState.java // public class ViewState { // // private final int visibility; // // private ViewState(int visibility) { // this.visibility = visibility; // } // // public int getVisibility() { // return visibility; // } // // public static class Builder { // private boolean isVisible; // // public Builder withVisible(boolean isVisible) { // this.isVisible = isVisible; // return this; // } // // public ViewState build() { // return new ViewState(isVisible ? View.VISIBLE : View.GONE); // } // } // }
import com.singhajit.sherlock.core.investigation.CrashViewModel; import com.singhajit.sherlock.crashes.util.ViewState; import java.util.List;
package com.singhajit.sherlock.crashes.viewmodel; public class CrashesViewModel { private final List<CrashViewModel> crashViewModels; public CrashesViewModel(List<CrashViewModel> crashViewModels) { this.crashViewModels = crashViewModels; } public List<CrashViewModel> getCrashViewModels() { return crashViewModels; }
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/investigation/CrashViewModel.java // public class CrashViewModel { // private Crash crash; // private AppInfoViewModel appInfoViewModel; // // public CrashViewModel() { // } // // public CrashViewModel(Crash crash) { // populate(crash); // } // // public String getPlace() { // String[] placeTrail = crash.getPlace().split("\\."); // return placeTrail[placeTrail.length - 1]; // } // // public String getExactLocationOfCrash() { // return crash.getPlace(); // } // // public String getReasonOfCrash() { // return crash.getReason(); // } // // public String getStackTrace() { // return crash.getStackTrace(); // } // // public String getCrashInfo() { // StringBuilder crashInfo = new StringBuilder(); // crashInfo.append("Device Info:\n"); // // crashInfo.append("Name: "); // crashInfo.append(getDeviceName() + "\n"); // // crashInfo.append("Brand: "); // crashInfo.append(getDeviceBrand() + "\n"); // // crashInfo.append("Android API: "); // crashInfo.append(getDeviceAndroidApiVersion() + "\n\n"); // // crashInfo.append("App Info:\n"); // crashInfo.append(getAppInfoViewModel().getDetails()); // crashInfo.append("\n"); // // crashInfo.append("StackTrace:\n"); // crashInfo.append(getStackTrace() + "\n"); // // return crashInfo.toString(); // } // // public String getDeviceManufacturer() { // return crash.getDeviceInfo().getManufacturer(); // } // // public String getDeviceName() { // return crash.getDeviceInfo().getName(); // } // // public String getDeviceAndroidApiVersion() { // return crash.getDeviceInfo().getSdk(); // } // // public String getDeviceBrand() { // return crash.getDeviceInfo().getBrand(); // } // // public AppInfoViewModel getAppInfoViewModel() { // return appInfoViewModel; // } // // public int getIdentifier() { // return crash.getId(); // } // // public String getDate() { // SimpleDateFormat simpleDateFormat = new SimpleDateFormat("h:mm a EEE, MMM d, yyyy"); // return simpleDateFormat.format(crash.getDate()); // } // // public void populate(Crash crash) { // this.crash = crash; // this.appInfoViewModel = new AppInfoViewModel(crash.getAppInfo()); // } // } // // Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/util/ViewState.java // public class ViewState { // // private final int visibility; // // private ViewState(int visibility) { // this.visibility = visibility; // } // // public int getVisibility() { // return visibility; // } // // public static class Builder { // private boolean isVisible; // // public Builder withVisible(boolean isVisible) { // this.isVisible = isVisible; // return this; // } // // public ViewState build() { // return new ViewState(isVisible ? View.VISIBLE : View.GONE); // } // } // } // Path: sherlock/src/main/java/com/singhajit/sherlock/crashes/viewmodel/CrashesViewModel.java import com.singhajit.sherlock.core.investigation.CrashViewModel; import com.singhajit.sherlock.crashes.util.ViewState; import java.util.List; package com.singhajit.sherlock.crashes.viewmodel; public class CrashesViewModel { private final List<CrashViewModel> crashViewModels; public CrashesViewModel(List<CrashViewModel> crashViewModels) { this.crashViewModels = crashViewModels; } public List<CrashViewModel> getCrashViewModels() { return crashViewModels; }
public ViewState getCrashNotFoundViewState() {
onepf/OPFPush
opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaNotificationsProviderStub.java
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // } // // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaPushConstants.java // public static final String PROVIDER_NAME = "Nokia Push";
import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker; import org.onepf.opfutils.OPFLog; import static org.onepf.opfpush.nokia.NokiaPushConstants.PROVIDER_NAME;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.nokia; /** * Nokia Notification push provider stub for not nokia devices. * * @author Roman Savin * @since 23.03.2015 */ class NokiaNotificationsProviderStub implements NokiaPushProvider { @Override public long getRegisterOnServerLifespan() { OPFLog.logMethod(); return 0; } @Override public void setRegisteredOnServer(@NonNull final Context context, final boolean flag) { OPFLog.logMethod(context, flag); } @Override public void setRegisterOnServerLifespan(@NonNull final Context context, final long lifespan) { OPFLog.logMethod(context, lifespan); } @Override public boolean isRegisterOnServer() { OPFLog.logMethod(); return false; } @Override public void register() { OPFLog.logMethod(); } @Override public void unregister() { OPFLog.logMethod(); } @NonNull @Override
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // } // // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaPushConstants.java // public static final String PROVIDER_NAME = "Nokia Push"; // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaNotificationsProviderStub.java import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker; import org.onepf.opfutils.OPFLog; import static org.onepf.opfpush.nokia.NokiaPushConstants.PROVIDER_NAME; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.nokia; /** * Nokia Notification push provider stub for not nokia devices. * * @author Roman Savin * @since 23.03.2015 */ class NokiaNotificationsProviderStub implements NokiaPushProvider { @Override public long getRegisterOnServerLifespan() { OPFLog.logMethod(); return 0; } @Override public void setRegisteredOnServer(@NonNull final Context context, final boolean flag) { OPFLog.logMethod(context, flag); } @Override public void setRegisterOnServerLifespan(@NonNull final Context context, final long lifespan) { OPFLog.logMethod(context, lifespan); } @Override public boolean isRegisterOnServer() { OPFLog.logMethod(); return false; } @Override public void register() { OPFLog.logMethod(); } @Override public void unregister() { OPFLog.logMethod(); } @NonNull @Override
public AvailabilityResult getAvailabilityResult() {
onepf/OPFPush
opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaNotificationsProviderStub.java
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // } // // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaPushConstants.java // public static final String PROVIDER_NAME = "Nokia Push";
import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker; import org.onepf.opfutils.OPFLog; import static org.onepf.opfpush.nokia.NokiaPushConstants.PROVIDER_NAME;
@Override public void unregister() { OPFLog.logMethod(); } @NonNull @Override public AvailabilityResult getAvailabilityResult() { OPFLog.logMethod(); return new AvailabilityResult(false); } @Override public boolean isRegistered() { OPFLog.logMethod(); return false; } @Nullable @Override public String getRegistrationId() { OPFLog.logMethod(); return null; } @NonNull @Override public String getName() { OPFLog.logMethod();
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // } // // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaPushConstants.java // public static final String PROVIDER_NAME = "Nokia Push"; // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaNotificationsProviderStub.java import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker; import org.onepf.opfutils.OPFLog; import static org.onepf.opfpush.nokia.NokiaPushConstants.PROVIDER_NAME; @Override public void unregister() { OPFLog.logMethod(); } @NonNull @Override public AvailabilityResult getAvailabilityResult() { OPFLog.logMethod(); return new AvailabilityResult(false); } @Override public boolean isRegistered() { OPFLog.logMethod(); return false; } @Nullable @Override public String getRegistrationId() { OPFLog.logMethod(); return null; } @NonNull @Override public String getName() { OPFLog.logMethod();
return PROVIDER_NAME;
onepf/OPFPush
opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaNotificationsProviderStub.java
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // } // // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaPushConstants.java // public static final String PROVIDER_NAME = "Nokia Push";
import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker; import org.onepf.opfutils.OPFLog; import static org.onepf.opfpush.nokia.NokiaPushConstants.PROVIDER_NAME;
@Override public boolean isRegistered() { OPFLog.logMethod(); return false; } @Nullable @Override public String getRegistrationId() { OPFLog.logMethod(); return null; } @NonNull @Override public String getName() { OPFLog.logMethod(); return PROVIDER_NAME; } @Nullable @Override public String getHostAppPackage() { OPFLog.logMethod(); return null; } @NonNull @Override
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // } // // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaPushConstants.java // public static final String PROVIDER_NAME = "Nokia Push"; // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaNotificationsProviderStub.java import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker; import org.onepf.opfutils.OPFLog; import static org.onepf.opfpush.nokia.NokiaPushConstants.PROVIDER_NAME; @Override public boolean isRegistered() { OPFLog.logMethod(); return false; } @Nullable @Override public String getRegistrationId() { OPFLog.logMethod(); return null; } @NonNull @Override public String getName() { OPFLog.logMethod(); return PROVIDER_NAME; } @Nullable @Override public String getHostAppPackage() { OPFLog.logMethod(); return null; } @NonNull @Override
public NotificationMaker getNotificationMaker() {
onepf/OPFPush
opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaNotificationsProviderStub.java
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // } // // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaPushConstants.java // public static final String PROVIDER_NAME = "Nokia Push";
import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker; import org.onepf.opfutils.OPFLog; import static org.onepf.opfpush.nokia.NokiaPushConstants.PROVIDER_NAME;
public String getName() { OPFLog.logMethod(); return PROVIDER_NAME; } @Nullable @Override public String getHostAppPackage() { OPFLog.logMethod(); return null; } @NonNull @Override public NotificationMaker getNotificationMaker() { OPFLog.logMethod(); return new NotificationMaker() { @Override public boolean needShowNotification(@NonNull Bundle bundle) { return false; } @Override public void showNotification(@NonNull Context context, @NonNull Bundle bundle) { //nothing } }; } @Override
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // } // // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaPushConstants.java // public static final String PROVIDER_NAME = "Nokia Push"; // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaNotificationsProviderStub.java import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker; import org.onepf.opfutils.OPFLog; import static org.onepf.opfpush.nokia.NokiaPushConstants.PROVIDER_NAME; public String getName() { OPFLog.logMethod(); return PROVIDER_NAME; } @Nullable @Override public String getHostAppPackage() { OPFLog.logMethod(); return null; } @NonNull @Override public NotificationMaker getNotificationMaker() { OPFLog.logMethod(); return new NotificationMaker() { @Override public boolean needShowNotification(@NonNull Bundle bundle) { return false; } @Override public void showNotification(@NonNull Context context, @NonNull Bundle bundle) { //nothing } }; } @Override
public void checkManifest(@Nullable final CheckManifestHandler checkManifestHandler) {
onepf/OPFPush
opfpush/src/main/java/org/onepf/opfpush/listener/SimpleEventListener.java
// Path: opfpush/src/main/java/org/onepf/opfpush/model/UnrecoverablePushError.java // public final class UnrecoverablePushError extends PushError<UnrecoverablePushError.Type> { // // @Nullable // private Integer availabilityErrorCode; // // public UnrecoverablePushError(@NonNull final Type type, // @NonNull final String providerName) { // this(type, providerName, type.name(), null); // } // // public UnrecoverablePushError(@NonNull final Type type, // @NonNull final String providerName, // @NonNull final String errorId) { // this(type, providerName, errorId, null); // } // // public UnrecoverablePushError(@NonNull final Type type, // @NonNull final String providerName, // @NonNull final Integer availabilityErrorCode) { // this(type, providerName, type.name(), availabilityErrorCode); // } // // public UnrecoverablePushError(@NonNull final Type type, // @NonNull final String providerName, // @NonNull final String errorId, // @Nullable final Integer availabilityErrorCode) { // super(type, providerName, errorId); // this.availabilityErrorCode = availabilityErrorCode; // } // // /** // * Returns an availability error code, or {@code null} if a provider hasn't returned a specific availability error. // * For GCM it corresponds to the {@code ConnectionResult} codes. // * // * @return The error code indicates the specific provider availability error. Can be {@code null}. // */ // @Nullable // public Integer getAvailabilityErrorCode() { // return availabilityErrorCode; // } // // @Override // public boolean isRecoverable() { // return false; // } // // @Override // public String toString() { // return String.format( // Locale.US, // "UnrecoverablePushError : \n" // + "{\"providerName\" : \"%1$s\",\n" // + "\"type\" : \"%2$s\",\n" // + "\"originalError\":\"%3$s\",\n" // + "\"availabilityErrorCode\":\"%4$s\"}", // providerName, // type, // originalError, // availabilityErrorCode); // } // // public enum Type implements ErrorType { // // /** // * Invalid parameters have been sent to register provider. // */ // INVALID_PARAMETERS, // // /** // * An invalid sender ID has been used for the registration. // */ // INVALID_SENDER, // // /** // * The authentication failure. // */ // AUTHENTICATION_FAILED, // // /** // * A provider specific error has occurred while a registration. // * Look {@link #getOriginalError()} for more information. // */ // PROVIDER_SPECIFIC_ERROR, // // /** // * Occurred when a provider is unavailable by provider specific error. // * Use {@link #getAvailabilityErrorCode()} to know about the reason of a provider unavailability. // */ // AVAILABILITY_ERROR // } // }
import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.model.UnrecoverablePushError; import java.util.Map;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.listener; /** * The default implementation of the {@link org.onepf.opfpush.listener.EventListener} interface. * * @author Roman Savin * @since 03.12.14 */ public class SimpleEventListener implements EventListener { @Override public void onMessage(@NonNull Context context, @NonNull String providerName, @Nullable Bundle extras) { //nothing } @Override public void onDeletedMessages(@NonNull Context context, @NonNull String providerName, int messagesCount) { //nothing } @Override public void onRegistered(@NonNull Context context, @NonNull String providerName, @NonNull String registrationId) { //nothing } @Override public void onUnregistered(@NonNull Context context, @NonNull String providerName, @Nullable String registrationId) { //nothing } @Override public void onNoAvailableProvider(@NonNull Context context,
// Path: opfpush/src/main/java/org/onepf/opfpush/model/UnrecoverablePushError.java // public final class UnrecoverablePushError extends PushError<UnrecoverablePushError.Type> { // // @Nullable // private Integer availabilityErrorCode; // // public UnrecoverablePushError(@NonNull final Type type, // @NonNull final String providerName) { // this(type, providerName, type.name(), null); // } // // public UnrecoverablePushError(@NonNull final Type type, // @NonNull final String providerName, // @NonNull final String errorId) { // this(type, providerName, errorId, null); // } // // public UnrecoverablePushError(@NonNull final Type type, // @NonNull final String providerName, // @NonNull final Integer availabilityErrorCode) { // this(type, providerName, type.name(), availabilityErrorCode); // } // // public UnrecoverablePushError(@NonNull final Type type, // @NonNull final String providerName, // @NonNull final String errorId, // @Nullable final Integer availabilityErrorCode) { // super(type, providerName, errorId); // this.availabilityErrorCode = availabilityErrorCode; // } // // /** // * Returns an availability error code, or {@code null} if a provider hasn't returned a specific availability error. // * For GCM it corresponds to the {@code ConnectionResult} codes. // * // * @return The error code indicates the specific provider availability error. Can be {@code null}. // */ // @Nullable // public Integer getAvailabilityErrorCode() { // return availabilityErrorCode; // } // // @Override // public boolean isRecoverable() { // return false; // } // // @Override // public String toString() { // return String.format( // Locale.US, // "UnrecoverablePushError : \n" // + "{\"providerName\" : \"%1$s\",\n" // + "\"type\" : \"%2$s\",\n" // + "\"originalError\":\"%3$s\",\n" // + "\"availabilityErrorCode\":\"%4$s\"}", // providerName, // type, // originalError, // availabilityErrorCode); // } // // public enum Type implements ErrorType { // // /** // * Invalid parameters have been sent to register provider. // */ // INVALID_PARAMETERS, // // /** // * An invalid sender ID has been used for the registration. // */ // INVALID_SENDER, // // /** // * The authentication failure. // */ // AUTHENTICATION_FAILED, // // /** // * A provider specific error has occurred while a registration. // * Look {@link #getOriginalError()} for more information. // */ // PROVIDER_SPECIFIC_ERROR, // // /** // * Occurred when a provider is unavailable by provider specific error. // * Use {@link #getAvailabilityErrorCode()} to know about the reason of a provider unavailability. // */ // AVAILABILITY_ERROR // } // } // Path: opfpush/src/main/java/org/onepf/opfpush/listener/SimpleEventListener.java import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.model.UnrecoverablePushError; import java.util.Map; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.listener; /** * The default implementation of the {@link org.onepf.opfpush.listener.EventListener} interface. * * @author Roman Savin * @since 03.12.14 */ public class SimpleEventListener implements EventListener { @Override public void onMessage(@NonNull Context context, @NonNull String providerName, @Nullable Bundle extras) { //nothing } @Override public void onDeletedMessages(@NonNull Context context, @NonNull String providerName, int messagesCount) { //nothing } @Override public void onRegistered(@NonNull Context context, @NonNull String providerName, @NonNull String registrationId) { //nothing } @Override public void onUnregistered(@NonNull Context context, @NonNull String providerName, @Nullable String registrationId) { //nothing } @Override public void onNoAvailableProvider(@NonNull Context context,
@NonNull Map<String, UnrecoverablePushError> pushErrors) {
onepf/OPFPush
opfpush/src/test/java/org/onepf/opfpush/BasePushProviderTest.java
// Path: opfpush/src/test/java/org/onepf/opfpush/mock/MockNamePushProvider.java // public class MockNamePushProvider extends BasePushProvider { // // public static final String DEFAULT_HOST_APP_PACKAGE = "org.onepf.store"; // // public MockNamePushProvider(@NonNull String name) { // this(name, DEFAULT_HOST_APP_PACKAGE); // } // // public MockNamePushProvider(@NonNull String name, // @NonNull String hostAppPackage) { // super(RuntimeEnvironment.application, name, hostAppPackage); // } // // @Override // public void register() { // //nothing // } // // @Override // public void unregister() { // //nothing // } // // @Override // public void onRegistrationInvalid() { // //nothing // } // // @Override // public void onUnavailable() { // //nothing // } // // @Override // public boolean isRegistered() { // return false; // } // // @Nullable // @Override // public String getRegistrationId() { // return null; // } // }
import junit.framework.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.onepf.opfpush.mock.MockNamePushProvider; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
package org.onepf.opfpush; /** * @author antonpp * @since 14.04.15 */ @Config(sdk = JELLY_BEAN_MR2, manifest = Config.NONE) @RunWith(RobolectricTestRunner.class) public class BasePushProviderTest { private BasePushProvider basePushProvider; @Before public void setUp() {
// Path: opfpush/src/test/java/org/onepf/opfpush/mock/MockNamePushProvider.java // public class MockNamePushProvider extends BasePushProvider { // // public static final String DEFAULT_HOST_APP_PACKAGE = "org.onepf.store"; // // public MockNamePushProvider(@NonNull String name) { // this(name, DEFAULT_HOST_APP_PACKAGE); // } // // public MockNamePushProvider(@NonNull String name, // @NonNull String hostAppPackage) { // super(RuntimeEnvironment.application, name, hostAppPackage); // } // // @Override // public void register() { // //nothing // } // // @Override // public void unregister() { // //nothing // } // // @Override // public void onRegistrationInvalid() { // //nothing // } // // @Override // public void onUnavailable() { // //nothing // } // // @Override // public boolean isRegistered() { // return false; // } // // @Nullable // @Override // public String getRegistrationId() { // return null; // } // } // Path: opfpush/src/test/java/org/onepf/opfpush/BasePushProviderTest.java import junit.framework.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.onepf.opfpush.mock.MockNamePushProvider; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR2; package org.onepf.opfpush; /** * @author antonpp * @since 14.04.15 */ @Config(sdk = JELLY_BEAN_MR2, manifest = Config.NONE) @RunWith(RobolectricTestRunner.class) public class BasePushProviderTest { private BasePushProvider basePushProvider; @Before public void setUp() {
basePushProvider = new MockNamePushProvider("Courier Push");
onepf/OPFPush
opfpush/src/main/java/org/onepf/opfpush/backoff/RegisterBackoffAdapter.java
// Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java // public enum Operation { // REGISTER, // UNREGISTER // }
import android.support.annotation.NonNull; import org.onepf.opfutils.OPFLog; import org.onepf.opfpush.model.Operation; import static org.onepf.opfpush.model.Operation.REGISTER;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.backoff; /** * @author Roman Savin * @since 04.02.2015 */ final class RegisterBackoffAdapter<T extends Backoff> implements BackoffManager { @NonNull private final Backoff registerBackoff; public RegisterBackoffAdapter(@NonNull final Class<T> backoffClass) { this.registerBackoff = createBackoff(backoffClass); } @Override
// Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java // public enum Operation { // REGISTER, // UNREGISTER // } // Path: opfpush/src/main/java/org/onepf/opfpush/backoff/RegisterBackoffAdapter.java import android.support.annotation.NonNull; import org.onepf.opfutils.OPFLog; import org.onepf.opfpush.model.Operation; import static org.onepf.opfpush.model.Operation.REGISTER; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.backoff; /** * @author Roman Savin * @since 04.02.2015 */ final class RegisterBackoffAdapter<T extends Backoff> implements BackoffManager { @NonNull private final Backoff registerBackoff; public RegisterBackoffAdapter(@NonNull final Class<T> backoffClass) { this.registerBackoff = createBackoff(backoffClass); } @Override
public boolean hasTries(@NonNull final String providerName, @NonNull final Operation operation) {
onepf/OPFPush
opfpush/src/main/java/org/onepf/opfpush/backoff/InfinityExponentialBackoffManager.java
// Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java // public enum Operation { // REGISTER, // UNREGISTER // }
import android.support.annotation.NonNull; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfpush.model.Operation;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.backoff; /** * @author Roman Savin * @since 04.02.2015 */ public final class InfinityExponentialBackoffManager implements BackoffManager { private static volatile InfinityExponentialBackoffManager instance; @NonNull private final BackoffManager registerBackoffAdapter; @NonNull private final BackoffManager unregisterBackoffAdapter; private InfinityExponentialBackoffManager() { registerBackoffAdapter = new RegisterBackoffAdapter<>(InfinityExponentialBackoff.class); unregisterBackoffAdapter = new UnregisterBackoffAdapter<>(InfinityExponentialBackoff.class); } @SuppressWarnings("PMD.NonThreadSafeSingleton") public static InfinityExponentialBackoffManager getInstance() { OPFChecks.checkThread(true); if (instance == null) { instance = new InfinityExponentialBackoffManager(); } return instance; } public boolean hasTries(@NonNull final String providerName,
// Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java // public enum Operation { // REGISTER, // UNREGISTER // } // Path: opfpush/src/main/java/org/onepf/opfpush/backoff/InfinityExponentialBackoffManager.java import android.support.annotation.NonNull; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfpush.model.Operation; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.backoff; /** * @author Roman Savin * @since 04.02.2015 */ public final class InfinityExponentialBackoffManager implements BackoffManager { private static volatile InfinityExponentialBackoffManager instance; @NonNull private final BackoffManager registerBackoffAdapter; @NonNull private final BackoffManager unregisterBackoffAdapter; private InfinityExponentialBackoffManager() { registerBackoffAdapter = new RegisterBackoffAdapter<>(InfinityExponentialBackoff.class); unregisterBackoffAdapter = new UnregisterBackoffAdapter<>(InfinityExponentialBackoff.class); } @SuppressWarnings("PMD.NonThreadSafeSingleton") public static InfinityExponentialBackoffManager getInstance() { OPFChecks.checkThread(true); if (instance == null) { instance = new InfinityExponentialBackoffManager(); } return instance; } public boolean hasTries(@NonNull final String providerName,
@NonNull final Operation operation) {
onepf/OPFPush
opfpush/src/test/java/org/onepf/opfpush/backoff/InfinityExponentialBackoffManagerTest.java
// Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java // public enum Operation { // REGISTER, // UNREGISTER // } // // Path: opfpush/src/test/java/org/onepf/opfpush/testutil/Util.java // public final class Util { // // public static final int NUM_TESTS = 100; // public static final int NUM_PROVIDERS = 100; // public static final int RANDOM_STRING_LENGTH = 16; // private static final Random RND = new Random(); // // private Util() { // throw new UnsupportedOperationException(); // } // // public static List<String> shuffleStringArray(final String[] array) { // final List<String> mixedArray = Arrays.asList(array); // Collections.shuffle(mixedArray); // return mixedArray; // } // // public static String[] getRandomStrings(int n, int len) { // char[] chars = "abcdefghijklmnopqrstuvwxyz0123456789".toCharArray(); // String[] strings = new String[n]; // for (int i = 0; i < n; ++i) { // StringBuilder sb = new StringBuilder(); // for (int j = 0; j < len; j++) { // char c = chars[RND.nextInt(chars.length)]; // sb.append(c); // } // strings[i] = sb.toString(); // } // return strings; // } // // public static PushProvider[] getRandomPushProviders() { // final MockNamePushProvider[] pushProviders = new MockNamePushProvider[NUM_PROVIDERS]; // for (int i = 0; i < NUM_PROVIDERS; ++i) { // pushProviders[i] = new MockNamePushProvider(String.format("provider%d", i + 1)); // } // return pushProviders; // } // }
import android.annotation.TargetApi; import android.os.Build; import android.util.Log; import junit.framework.Assert; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.onepf.opfpush.model.Operation; import org.onepf.opfpush.testutil.Util; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import java.lang.reflect.Field; import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
private InfinityExponentialBackoffManager manager; @Before public void setUp() { manager = InfinityExponentialBackoffManager.getInstance(); } @TargetApi(Build.VERSION_CODES.KITKAT) @After public void eraseSettingsInstance() { synchronized (InfinityExponentialBackoffManager.class) { try { final Field instanceField = InfinityExponentialBackoffManager.class.getDeclaredField("instance"); instanceField.setAccessible(true); instanceField.set(null, null); } catch (IllegalAccessException | NoSuchFieldException e) { Log.e(TAG, e.getMessage()); } } } @Test public void testGetInstance() { eraseSettingsInstance(); manager = InfinityExponentialBackoffManager.getInstance(); assertEquals(manager, InfinityExponentialBackoffManager.getInstance()); } @Test public void testHasTries() {
// Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java // public enum Operation { // REGISTER, // UNREGISTER // } // // Path: opfpush/src/test/java/org/onepf/opfpush/testutil/Util.java // public final class Util { // // public static final int NUM_TESTS = 100; // public static final int NUM_PROVIDERS = 100; // public static final int RANDOM_STRING_LENGTH = 16; // private static final Random RND = new Random(); // // private Util() { // throw new UnsupportedOperationException(); // } // // public static List<String> shuffleStringArray(final String[] array) { // final List<String> mixedArray = Arrays.asList(array); // Collections.shuffle(mixedArray); // return mixedArray; // } // // public static String[] getRandomStrings(int n, int len) { // char[] chars = "abcdefghijklmnopqrstuvwxyz0123456789".toCharArray(); // String[] strings = new String[n]; // for (int i = 0; i < n; ++i) { // StringBuilder sb = new StringBuilder(); // for (int j = 0; j < len; j++) { // char c = chars[RND.nextInt(chars.length)]; // sb.append(c); // } // strings[i] = sb.toString(); // } // return strings; // } // // public static PushProvider[] getRandomPushProviders() { // final MockNamePushProvider[] pushProviders = new MockNamePushProvider[NUM_PROVIDERS]; // for (int i = 0; i < NUM_PROVIDERS; ++i) { // pushProviders[i] = new MockNamePushProvider(String.format("provider%d", i + 1)); // } // return pushProviders; // } // } // Path: opfpush/src/test/java/org/onepf/opfpush/backoff/InfinityExponentialBackoffManagerTest.java import android.annotation.TargetApi; import android.os.Build; import android.util.Log; import junit.framework.Assert; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.onepf.opfpush.model.Operation; import org.onepf.opfpush.testutil.Util; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import java.lang.reflect.Field; import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR2; private InfinityExponentialBackoffManager manager; @Before public void setUp() { manager = InfinityExponentialBackoffManager.getInstance(); } @TargetApi(Build.VERSION_CODES.KITKAT) @After public void eraseSettingsInstance() { synchronized (InfinityExponentialBackoffManager.class) { try { final Field instanceField = InfinityExponentialBackoffManager.class.getDeclaredField("instance"); instanceField.setAccessible(true); instanceField.set(null, null); } catch (IllegalAccessException | NoSuchFieldException e) { Log.e(TAG, e.getMessage()); } } } @Test public void testGetInstance() { eraseSettingsInstance(); manager = InfinityExponentialBackoffManager.getInstance(); assertEquals(manager, InfinityExponentialBackoffManager.getInstance()); } @Test public void testHasTries() {
for (int i = 0; i < Util.NUM_TESTS; ++i) {
onepf/OPFPush
opfpush/src/test/java/org/onepf/opfpush/backoff/InfinityExponentialBackoffManagerTest.java
// Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java // public enum Operation { // REGISTER, // UNREGISTER // } // // Path: opfpush/src/test/java/org/onepf/opfpush/testutil/Util.java // public final class Util { // // public static final int NUM_TESTS = 100; // public static final int NUM_PROVIDERS = 100; // public static final int RANDOM_STRING_LENGTH = 16; // private static final Random RND = new Random(); // // private Util() { // throw new UnsupportedOperationException(); // } // // public static List<String> shuffleStringArray(final String[] array) { // final List<String> mixedArray = Arrays.asList(array); // Collections.shuffle(mixedArray); // return mixedArray; // } // // public static String[] getRandomStrings(int n, int len) { // char[] chars = "abcdefghijklmnopqrstuvwxyz0123456789".toCharArray(); // String[] strings = new String[n]; // for (int i = 0; i < n; ++i) { // StringBuilder sb = new StringBuilder(); // for (int j = 0; j < len; j++) { // char c = chars[RND.nextInt(chars.length)]; // sb.append(c); // } // strings[i] = sb.toString(); // } // return strings; // } // // public static PushProvider[] getRandomPushProviders() { // final MockNamePushProvider[] pushProviders = new MockNamePushProvider[NUM_PROVIDERS]; // for (int i = 0; i < NUM_PROVIDERS; ++i) { // pushProviders[i] = new MockNamePushProvider(String.format("provider%d", i + 1)); // } // return pushProviders; // } // }
import android.annotation.TargetApi; import android.os.Build; import android.util.Log; import junit.framework.Assert; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.onepf.opfpush.model.Operation; import org.onepf.opfpush.testutil.Util; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import java.lang.reflect.Field; import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
@Before public void setUp() { manager = InfinityExponentialBackoffManager.getInstance(); } @TargetApi(Build.VERSION_CODES.KITKAT) @After public void eraseSettingsInstance() { synchronized (InfinityExponentialBackoffManager.class) { try { final Field instanceField = InfinityExponentialBackoffManager.class.getDeclaredField("instance"); instanceField.setAccessible(true); instanceField.set(null, null); } catch (IllegalAccessException | NoSuchFieldException e) { Log.e(TAG, e.getMessage()); } } } @Test public void testGetInstance() { eraseSettingsInstance(); manager = InfinityExponentialBackoffManager.getInstance(); assertEquals(manager, InfinityExponentialBackoffManager.getInstance()); } @Test public void testHasTries() { for (int i = 0; i < Util.NUM_TESTS; ++i) {
// Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java // public enum Operation { // REGISTER, // UNREGISTER // } // // Path: opfpush/src/test/java/org/onepf/opfpush/testutil/Util.java // public final class Util { // // public static final int NUM_TESTS = 100; // public static final int NUM_PROVIDERS = 100; // public static final int RANDOM_STRING_LENGTH = 16; // private static final Random RND = new Random(); // // private Util() { // throw new UnsupportedOperationException(); // } // // public static List<String> shuffleStringArray(final String[] array) { // final List<String> mixedArray = Arrays.asList(array); // Collections.shuffle(mixedArray); // return mixedArray; // } // // public static String[] getRandomStrings(int n, int len) { // char[] chars = "abcdefghijklmnopqrstuvwxyz0123456789".toCharArray(); // String[] strings = new String[n]; // for (int i = 0; i < n; ++i) { // StringBuilder sb = new StringBuilder(); // for (int j = 0; j < len; j++) { // char c = chars[RND.nextInt(chars.length)]; // sb.append(c); // } // strings[i] = sb.toString(); // } // return strings; // } // // public static PushProvider[] getRandomPushProviders() { // final MockNamePushProvider[] pushProviders = new MockNamePushProvider[NUM_PROVIDERS]; // for (int i = 0; i < NUM_PROVIDERS; ++i) { // pushProviders[i] = new MockNamePushProvider(String.format("provider%d", i + 1)); // } // return pushProviders; // } // } // Path: opfpush/src/test/java/org/onepf/opfpush/backoff/InfinityExponentialBackoffManagerTest.java import android.annotation.TargetApi; import android.os.Build; import android.util.Log; import junit.framework.Assert; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.onepf.opfpush.model.Operation; import org.onepf.opfpush.testutil.Util; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import java.lang.reflect.Field; import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR2; @Before public void setUp() { manager = InfinityExponentialBackoffManager.getInstance(); } @TargetApi(Build.VERSION_CODES.KITKAT) @After public void eraseSettingsInstance() { synchronized (InfinityExponentialBackoffManager.class) { try { final Field instanceField = InfinityExponentialBackoffManager.class.getDeclaredField("instance"); instanceField.setAccessible(true); instanceField.set(null, null); } catch (IllegalAccessException | NoSuchFieldException e) { Log.e(TAG, e.getMessage()); } } } @Test public void testGetInstance() { eraseSettingsInstance(); manager = InfinityExponentialBackoffManager.getInstance(); assertEquals(manager, InfinityExponentialBackoffManager.getInstance()); } @Test public void testHasTries() { for (int i = 0; i < Util.NUM_TESTS; ++i) {
for (final Operation operation : Operation.values()) {
onepf/OPFPush
samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactsContract { // public static final String TABLE_NAME = "contacts"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 2; // public static final int URI_CODE = 3; // // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessagesContract { // public static final String TABLE_NAME = "messages"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 0; // public static final int URI_CODE = 1; // // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java // public interface QueryContactsUuidsCallback { // // void onComplete(@NonNull final Set<String> uuids); // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Contact.java // public final class Contact { // // @NonNull // private final String name; // // @NonNull // private final String uuid; // // public Contact(@NonNull final String name, @NonNull final String uuid) { // this.name = name; // this.uuid = uuid; // } // // @NonNull // public String getName() { // return name; // } // // @NonNull // public String getUuid() { // return uuid; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Message.java // public final class Message { // // @NonNull // private final String senderUuid; // // @NonNull // private final String messageText; // // private final long receivedTime; // // public Message(@NonNull final String senderUuid, // @NonNull final String messageText, // final long receivedTime) { // this.senderUuid = senderUuid; // this.messageText = messageText; // this.receivedTime = receivedTime; // } // // @NonNull // public String getSenderUuid() { // return senderUuid; // } // // @NonNull // public String getMessageText() { // return messageText; // } // // public long getReceivedTime() { // return receivedTime; // } // }
import org.onepf.pushchat.model.db.Message; import java.util.HashSet; import java.util.Set; import android.content.AsyncQueryHandler; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.support.annotation.NonNull; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract.MessageEntry; import org.onepf.pushchat.db.DatabaseHelper.ContactsUuidsAsyncQueryHandler.QueryContactsUuidsCallback; import org.onepf.pushchat.model.db.Contact;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.pushchat.db; /** * @author Roman Savin * @since 06.05.2015 */ @SuppressWarnings("PMD.NonThreadSafeSingleton") public final class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "org.onepf.pushchat.db"; private static final int DATABASE_VERSION = 1; private static final String COMMA_SEP = ","; private static final String SQL_CREATE_CONTACTS_TABLE =
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactsContract { // public static final String TABLE_NAME = "contacts"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 2; // public static final int URI_CODE = 3; // // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessagesContract { // public static final String TABLE_NAME = "messages"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 0; // public static final int URI_CODE = 1; // // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java // public interface QueryContactsUuidsCallback { // // void onComplete(@NonNull final Set<String> uuids); // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Contact.java // public final class Contact { // // @NonNull // private final String name; // // @NonNull // private final String uuid; // // public Contact(@NonNull final String name, @NonNull final String uuid) { // this.name = name; // this.uuid = uuid; // } // // @NonNull // public String getName() { // return name; // } // // @NonNull // public String getUuid() { // return uuid; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Message.java // public final class Message { // // @NonNull // private final String senderUuid; // // @NonNull // private final String messageText; // // private final long receivedTime; // // public Message(@NonNull final String senderUuid, // @NonNull final String messageText, // final long receivedTime) { // this.senderUuid = senderUuid; // this.messageText = messageText; // this.receivedTime = receivedTime; // } // // @NonNull // public String getSenderUuid() { // return senderUuid; // } // // @NonNull // public String getMessageText() { // return messageText; // } // // public long getReceivedTime() { // return receivedTime; // } // } // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java import org.onepf.pushchat.model.db.Message; import java.util.HashSet; import java.util.Set; import android.content.AsyncQueryHandler; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.support.annotation.NonNull; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract.MessageEntry; import org.onepf.pushchat.db.DatabaseHelper.ContactsUuidsAsyncQueryHandler.QueryContactsUuidsCallback; import org.onepf.pushchat.model.db.Contact; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.pushchat.db; /** * @author Roman Savin * @since 06.05.2015 */ @SuppressWarnings("PMD.NonThreadSafeSingleton") public final class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "org.onepf.pushchat.db"; private static final int DATABASE_VERSION = 1; private static final String COMMA_SEP = ","; private static final String SQL_CREATE_CONTACTS_TABLE =
"CREATE TABLE " + ContactsContract.TABLE_NAME + " ( "
onepf/OPFPush
samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactsContract { // public static final String TABLE_NAME = "contacts"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 2; // public static final int URI_CODE = 3; // // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessagesContract { // public static final String TABLE_NAME = "messages"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 0; // public static final int URI_CODE = 1; // // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java // public interface QueryContactsUuidsCallback { // // void onComplete(@NonNull final Set<String> uuids); // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Contact.java // public final class Contact { // // @NonNull // private final String name; // // @NonNull // private final String uuid; // // public Contact(@NonNull final String name, @NonNull final String uuid) { // this.name = name; // this.uuid = uuid; // } // // @NonNull // public String getName() { // return name; // } // // @NonNull // public String getUuid() { // return uuid; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Message.java // public final class Message { // // @NonNull // private final String senderUuid; // // @NonNull // private final String messageText; // // private final long receivedTime; // // public Message(@NonNull final String senderUuid, // @NonNull final String messageText, // final long receivedTime) { // this.senderUuid = senderUuid; // this.messageText = messageText; // this.receivedTime = receivedTime; // } // // @NonNull // public String getSenderUuid() { // return senderUuid; // } // // @NonNull // public String getMessageText() { // return messageText; // } // // public long getReceivedTime() { // return receivedTime; // } // }
import org.onepf.pushchat.model.db.Message; import java.util.HashSet; import java.util.Set; import android.content.AsyncQueryHandler; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.support.annotation.NonNull; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract.MessageEntry; import org.onepf.pushchat.db.DatabaseHelper.ContactsUuidsAsyncQueryHandler.QueryContactsUuidsCallback; import org.onepf.pushchat.model.db.Contact;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.pushchat.db; /** * @author Roman Savin * @since 06.05.2015 */ @SuppressWarnings("PMD.NonThreadSafeSingleton") public final class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "org.onepf.pushchat.db"; private static final int DATABASE_VERSION = 1; private static final String COMMA_SEP = ","; private static final String SQL_CREATE_CONTACTS_TABLE = "CREATE TABLE " + ContactsContract.TABLE_NAME + " ( "
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactsContract { // public static final String TABLE_NAME = "contacts"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 2; // public static final int URI_CODE = 3; // // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessagesContract { // public static final String TABLE_NAME = "messages"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 0; // public static final int URI_CODE = 1; // // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java // public interface QueryContactsUuidsCallback { // // void onComplete(@NonNull final Set<String> uuids); // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Contact.java // public final class Contact { // // @NonNull // private final String name; // // @NonNull // private final String uuid; // // public Contact(@NonNull final String name, @NonNull final String uuid) { // this.name = name; // this.uuid = uuid; // } // // @NonNull // public String getName() { // return name; // } // // @NonNull // public String getUuid() { // return uuid; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Message.java // public final class Message { // // @NonNull // private final String senderUuid; // // @NonNull // private final String messageText; // // private final long receivedTime; // // public Message(@NonNull final String senderUuid, // @NonNull final String messageText, // final long receivedTime) { // this.senderUuid = senderUuid; // this.messageText = messageText; // this.receivedTime = receivedTime; // } // // @NonNull // public String getSenderUuid() { // return senderUuid; // } // // @NonNull // public String getMessageText() { // return messageText; // } // // public long getReceivedTime() { // return receivedTime; // } // } // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java import org.onepf.pushchat.model.db.Message; import java.util.HashSet; import java.util.Set; import android.content.AsyncQueryHandler; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.support.annotation.NonNull; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract.MessageEntry; import org.onepf.pushchat.db.DatabaseHelper.ContactsUuidsAsyncQueryHandler.QueryContactsUuidsCallback; import org.onepf.pushchat.model.db.Contact; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.pushchat.db; /** * @author Roman Savin * @since 06.05.2015 */ @SuppressWarnings("PMD.NonThreadSafeSingleton") public final class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "org.onepf.pushchat.db"; private static final int DATABASE_VERSION = 1; private static final String COMMA_SEP = ","; private static final String SQL_CREATE_CONTACTS_TABLE = "CREATE TABLE " + ContactsContract.TABLE_NAME + " ( "
+ ContactEntry.ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL" + COMMA_SEP
onepf/OPFPush
samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactsContract { // public static final String TABLE_NAME = "contacts"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 2; // public static final int URI_CODE = 3; // // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessagesContract { // public static final String TABLE_NAME = "messages"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 0; // public static final int URI_CODE = 1; // // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java // public interface QueryContactsUuidsCallback { // // void onComplete(@NonNull final Set<String> uuids); // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Contact.java // public final class Contact { // // @NonNull // private final String name; // // @NonNull // private final String uuid; // // public Contact(@NonNull final String name, @NonNull final String uuid) { // this.name = name; // this.uuid = uuid; // } // // @NonNull // public String getName() { // return name; // } // // @NonNull // public String getUuid() { // return uuid; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Message.java // public final class Message { // // @NonNull // private final String senderUuid; // // @NonNull // private final String messageText; // // private final long receivedTime; // // public Message(@NonNull final String senderUuid, // @NonNull final String messageText, // final long receivedTime) { // this.senderUuid = senderUuid; // this.messageText = messageText; // this.receivedTime = receivedTime; // } // // @NonNull // public String getSenderUuid() { // return senderUuid; // } // // @NonNull // public String getMessageText() { // return messageText; // } // // public long getReceivedTime() { // return receivedTime; // } // }
import org.onepf.pushchat.model.db.Message; import java.util.HashSet; import java.util.Set; import android.content.AsyncQueryHandler; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.support.annotation.NonNull; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract.MessageEntry; import org.onepf.pushchat.db.DatabaseHelper.ContactsUuidsAsyncQueryHandler.QueryContactsUuidsCallback; import org.onepf.pushchat.model.db.Contact;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.pushchat.db; /** * @author Roman Savin * @since 06.05.2015 */ @SuppressWarnings("PMD.NonThreadSafeSingleton") public final class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "org.onepf.pushchat.db"; private static final int DATABASE_VERSION = 1; private static final String COMMA_SEP = ","; private static final String SQL_CREATE_CONTACTS_TABLE = "CREATE TABLE " + ContactsContract.TABLE_NAME + " ( " + ContactEntry.ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL" + COMMA_SEP + ContactEntry.NAME + " TEXT" + COMMA_SEP + ContactEntry.UUID + " TEXT UNIQUE NOT NULL" + " )"; private static final String SQL_CREATE_MESSAGES_TABLE =
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactsContract { // public static final String TABLE_NAME = "contacts"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 2; // public static final int URI_CODE = 3; // // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessagesContract { // public static final String TABLE_NAME = "messages"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 0; // public static final int URI_CODE = 1; // // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java // public interface QueryContactsUuidsCallback { // // void onComplete(@NonNull final Set<String> uuids); // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Contact.java // public final class Contact { // // @NonNull // private final String name; // // @NonNull // private final String uuid; // // public Contact(@NonNull final String name, @NonNull final String uuid) { // this.name = name; // this.uuid = uuid; // } // // @NonNull // public String getName() { // return name; // } // // @NonNull // public String getUuid() { // return uuid; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Message.java // public final class Message { // // @NonNull // private final String senderUuid; // // @NonNull // private final String messageText; // // private final long receivedTime; // // public Message(@NonNull final String senderUuid, // @NonNull final String messageText, // final long receivedTime) { // this.senderUuid = senderUuid; // this.messageText = messageText; // this.receivedTime = receivedTime; // } // // @NonNull // public String getSenderUuid() { // return senderUuid; // } // // @NonNull // public String getMessageText() { // return messageText; // } // // public long getReceivedTime() { // return receivedTime; // } // } // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java import org.onepf.pushchat.model.db.Message; import java.util.HashSet; import java.util.Set; import android.content.AsyncQueryHandler; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.support.annotation.NonNull; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract.MessageEntry; import org.onepf.pushchat.db.DatabaseHelper.ContactsUuidsAsyncQueryHandler.QueryContactsUuidsCallback; import org.onepf.pushchat.model.db.Contact; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.pushchat.db; /** * @author Roman Savin * @since 06.05.2015 */ @SuppressWarnings("PMD.NonThreadSafeSingleton") public final class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "org.onepf.pushchat.db"; private static final int DATABASE_VERSION = 1; private static final String COMMA_SEP = ","; private static final String SQL_CREATE_CONTACTS_TABLE = "CREATE TABLE " + ContactsContract.TABLE_NAME + " ( " + ContactEntry.ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL" + COMMA_SEP + ContactEntry.NAME + " TEXT" + COMMA_SEP + ContactEntry.UUID + " TEXT UNIQUE NOT NULL" + " )"; private static final String SQL_CREATE_MESSAGES_TABLE =
"CREATE TABLE " + MessagesContract.TABLE_NAME + " ( "
onepf/OPFPush
samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactsContract { // public static final String TABLE_NAME = "contacts"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 2; // public static final int URI_CODE = 3; // // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessagesContract { // public static final String TABLE_NAME = "messages"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 0; // public static final int URI_CODE = 1; // // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java // public interface QueryContactsUuidsCallback { // // void onComplete(@NonNull final Set<String> uuids); // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Contact.java // public final class Contact { // // @NonNull // private final String name; // // @NonNull // private final String uuid; // // public Contact(@NonNull final String name, @NonNull final String uuid) { // this.name = name; // this.uuid = uuid; // } // // @NonNull // public String getName() { // return name; // } // // @NonNull // public String getUuid() { // return uuid; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Message.java // public final class Message { // // @NonNull // private final String senderUuid; // // @NonNull // private final String messageText; // // private final long receivedTime; // // public Message(@NonNull final String senderUuid, // @NonNull final String messageText, // final long receivedTime) { // this.senderUuid = senderUuid; // this.messageText = messageText; // this.receivedTime = receivedTime; // } // // @NonNull // public String getSenderUuid() { // return senderUuid; // } // // @NonNull // public String getMessageText() { // return messageText; // } // // public long getReceivedTime() { // return receivedTime; // } // }
import org.onepf.pushchat.model.db.Message; import java.util.HashSet; import java.util.Set; import android.content.AsyncQueryHandler; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.support.annotation.NonNull; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract.MessageEntry; import org.onepf.pushchat.db.DatabaseHelper.ContactsUuidsAsyncQueryHandler.QueryContactsUuidsCallback; import org.onepf.pushchat.model.db.Contact;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.pushchat.db; /** * @author Roman Savin * @since 06.05.2015 */ @SuppressWarnings("PMD.NonThreadSafeSingleton") public final class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "org.onepf.pushchat.db"; private static final int DATABASE_VERSION = 1; private static final String COMMA_SEP = ","; private static final String SQL_CREATE_CONTACTS_TABLE = "CREATE TABLE " + ContactsContract.TABLE_NAME + " ( " + ContactEntry.ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL" + COMMA_SEP + ContactEntry.NAME + " TEXT" + COMMA_SEP + ContactEntry.UUID + " TEXT UNIQUE NOT NULL" + " )"; private static final String SQL_CREATE_MESSAGES_TABLE = "CREATE TABLE " + MessagesContract.TABLE_NAME + " ( "
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactsContract { // public static final String TABLE_NAME = "contacts"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 2; // public static final int URI_CODE = 3; // // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessagesContract { // public static final String TABLE_NAME = "messages"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 0; // public static final int URI_CODE = 1; // // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java // public interface QueryContactsUuidsCallback { // // void onComplete(@NonNull final Set<String> uuids); // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Contact.java // public final class Contact { // // @NonNull // private final String name; // // @NonNull // private final String uuid; // // public Contact(@NonNull final String name, @NonNull final String uuid) { // this.name = name; // this.uuid = uuid; // } // // @NonNull // public String getName() { // return name; // } // // @NonNull // public String getUuid() { // return uuid; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Message.java // public final class Message { // // @NonNull // private final String senderUuid; // // @NonNull // private final String messageText; // // private final long receivedTime; // // public Message(@NonNull final String senderUuid, // @NonNull final String messageText, // final long receivedTime) { // this.senderUuid = senderUuid; // this.messageText = messageText; // this.receivedTime = receivedTime; // } // // @NonNull // public String getSenderUuid() { // return senderUuid; // } // // @NonNull // public String getMessageText() { // return messageText; // } // // public long getReceivedTime() { // return receivedTime; // } // } // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java import org.onepf.pushchat.model.db.Message; import java.util.HashSet; import java.util.Set; import android.content.AsyncQueryHandler; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.support.annotation.NonNull; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract.MessageEntry; import org.onepf.pushchat.db.DatabaseHelper.ContactsUuidsAsyncQueryHandler.QueryContactsUuidsCallback; import org.onepf.pushchat.model.db.Contact; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.pushchat.db; /** * @author Roman Savin * @since 06.05.2015 */ @SuppressWarnings("PMD.NonThreadSafeSingleton") public final class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "org.onepf.pushchat.db"; private static final int DATABASE_VERSION = 1; private static final String COMMA_SEP = ","; private static final String SQL_CREATE_CONTACTS_TABLE = "CREATE TABLE " + ContactsContract.TABLE_NAME + " ( " + ContactEntry.ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL" + COMMA_SEP + ContactEntry.NAME + " TEXT" + COMMA_SEP + ContactEntry.UUID + " TEXT UNIQUE NOT NULL" + " )"; private static final String SQL_CREATE_MESSAGES_TABLE = "CREATE TABLE " + MessagesContract.TABLE_NAME + " ( "
+ MessageEntry.ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL" + COMMA_SEP
onepf/OPFPush
samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactsContract { // public static final String TABLE_NAME = "contacts"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 2; // public static final int URI_CODE = 3; // // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessagesContract { // public static final String TABLE_NAME = "messages"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 0; // public static final int URI_CODE = 1; // // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java // public interface QueryContactsUuidsCallback { // // void onComplete(@NonNull final Set<String> uuids); // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Contact.java // public final class Contact { // // @NonNull // private final String name; // // @NonNull // private final String uuid; // // public Contact(@NonNull final String name, @NonNull final String uuid) { // this.name = name; // this.uuid = uuid; // } // // @NonNull // public String getName() { // return name; // } // // @NonNull // public String getUuid() { // return uuid; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Message.java // public final class Message { // // @NonNull // private final String senderUuid; // // @NonNull // private final String messageText; // // private final long receivedTime; // // public Message(@NonNull final String senderUuid, // @NonNull final String messageText, // final long receivedTime) { // this.senderUuid = senderUuid; // this.messageText = messageText; // this.receivedTime = receivedTime; // } // // @NonNull // public String getSenderUuid() { // return senderUuid; // } // // @NonNull // public String getMessageText() { // return messageText; // } // // public long getReceivedTime() { // return receivedTime; // } // }
import org.onepf.pushchat.model.db.Message; import java.util.HashSet; import java.util.Set; import android.content.AsyncQueryHandler; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.support.annotation.NonNull; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract.MessageEntry; import org.onepf.pushchat.db.DatabaseHelper.ContactsUuidsAsyncQueryHandler.QueryContactsUuidsCallback; import org.onepf.pushchat.model.db.Contact;
public static DatabaseHelper getInstance(@NonNull final Context context) { if (instance == null) { synchronized (DatabaseHelper.class) { if (instance == null) { instance = new DatabaseHelper(context); } } } return instance; } @Override public void onCreate(@NonNull final SQLiteDatabase sqLiteDatabase) { sqLiteDatabase.execSQL(SQL_CREATE_CONTACTS_TABLE); sqLiteDatabase.execSQL(SQL_CREATE_MESSAGES_TABLE); } @Override public void onUpgrade(@NonNull final SQLiteDatabase sqLiteDatabase, final int oldVersion, final int newVersion) { if (oldVersion < newVersion) { sqLiteDatabase.execSQL(SQL_DELETE_MESSAGES_TABLE); sqLiteDatabase.execSQL(SQL_DELETE_CONTACTS_TABLE); onCreate(sqLiteDatabase); } }
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactsContract { // public static final String TABLE_NAME = "contacts"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 2; // public static final int URI_CODE = 3; // // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessagesContract { // public static final String TABLE_NAME = "messages"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 0; // public static final int URI_CODE = 1; // // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java // public interface QueryContactsUuidsCallback { // // void onComplete(@NonNull final Set<String> uuids); // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Contact.java // public final class Contact { // // @NonNull // private final String name; // // @NonNull // private final String uuid; // // public Contact(@NonNull final String name, @NonNull final String uuid) { // this.name = name; // this.uuid = uuid; // } // // @NonNull // public String getName() { // return name; // } // // @NonNull // public String getUuid() { // return uuid; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Message.java // public final class Message { // // @NonNull // private final String senderUuid; // // @NonNull // private final String messageText; // // private final long receivedTime; // // public Message(@NonNull final String senderUuid, // @NonNull final String messageText, // final long receivedTime) { // this.senderUuid = senderUuid; // this.messageText = messageText; // this.receivedTime = receivedTime; // } // // @NonNull // public String getSenderUuid() { // return senderUuid; // } // // @NonNull // public String getMessageText() { // return messageText; // } // // public long getReceivedTime() { // return receivedTime; // } // } // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java import org.onepf.pushchat.model.db.Message; import java.util.HashSet; import java.util.Set; import android.content.AsyncQueryHandler; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.support.annotation.NonNull; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract.MessageEntry; import org.onepf.pushchat.db.DatabaseHelper.ContactsUuidsAsyncQueryHandler.QueryContactsUuidsCallback; import org.onepf.pushchat.model.db.Contact; public static DatabaseHelper getInstance(@NonNull final Context context) { if (instance == null) { synchronized (DatabaseHelper.class) { if (instance == null) { instance = new DatabaseHelper(context); } } } return instance; } @Override public void onCreate(@NonNull final SQLiteDatabase sqLiteDatabase) { sqLiteDatabase.execSQL(SQL_CREATE_CONTACTS_TABLE); sqLiteDatabase.execSQL(SQL_CREATE_MESSAGES_TABLE); } @Override public void onUpgrade(@NonNull final SQLiteDatabase sqLiteDatabase, final int oldVersion, final int newVersion) { if (oldVersion < newVersion) { sqLiteDatabase.execSQL(SQL_DELETE_MESSAGES_TABLE); sqLiteDatabase.execSQL(SQL_DELETE_CONTACTS_TABLE); onCreate(sqLiteDatabase); } }
public void addMessage(@NonNull final Message message) {
onepf/OPFPush
samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactsContract { // public static final String TABLE_NAME = "contacts"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 2; // public static final int URI_CODE = 3; // // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessagesContract { // public static final String TABLE_NAME = "messages"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 0; // public static final int URI_CODE = 1; // // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java // public interface QueryContactsUuidsCallback { // // void onComplete(@NonNull final Set<String> uuids); // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Contact.java // public final class Contact { // // @NonNull // private final String name; // // @NonNull // private final String uuid; // // public Contact(@NonNull final String name, @NonNull final String uuid) { // this.name = name; // this.uuid = uuid; // } // // @NonNull // public String getName() { // return name; // } // // @NonNull // public String getUuid() { // return uuid; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Message.java // public final class Message { // // @NonNull // private final String senderUuid; // // @NonNull // private final String messageText; // // private final long receivedTime; // // public Message(@NonNull final String senderUuid, // @NonNull final String messageText, // final long receivedTime) { // this.senderUuid = senderUuid; // this.messageText = messageText; // this.receivedTime = receivedTime; // } // // @NonNull // public String getSenderUuid() { // return senderUuid; // } // // @NonNull // public String getMessageText() { // return messageText; // } // // public long getReceivedTime() { // return receivedTime; // } // }
import org.onepf.pushchat.model.db.Message; import java.util.HashSet; import java.util.Set; import android.content.AsyncQueryHandler; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.support.annotation.NonNull; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract.MessageEntry; import org.onepf.pushchat.db.DatabaseHelper.ContactsUuidsAsyncQueryHandler.QueryContactsUuidsCallback; import org.onepf.pushchat.model.db.Contact;
null, ContactsContract.TABLE_URI, new String[]{ContactEntry.NAME}, ContactEntry.UUID + "=?", new String[]{message.getSenderUuid()}, null ); } private QueryContactNameQueryHandler.QueryContactNameCallback queryContactNameCallback( @NonNull final Message message ) { return new QueryContactNameQueryHandler.QueryContactNameCallback() { @Override public void onComplete(@NonNull final String name) { final ContentValues contentValues = new ContentValues(); contentValues.put(MessageEntry.SENDER_UUID, message.getSenderUuid()); contentValues.put(MessageEntry.SENDER_NAME, name); contentValues.put(MessageEntry.MESSAGE, message.getMessageText()); contentValues.put(MessageEntry.RECEIVED_TIME, message.getReceivedTime()); asyncQueryHandler.startInsert(MESSAGE_OPERATION_TOKEN, null, MessagesContract.TABLE_URI, contentValues); } }; } public void deleteMessages() { asyncQueryHandler.startDelete(MESSAGE_OPERATION_TOKEN, null, MessagesContract.TABLE_URI, null, null); }
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactsContract { // public static final String TABLE_NAME = "contacts"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 2; // public static final int URI_CODE = 3; // // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessagesContract { // public static final String TABLE_NAME = "messages"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 0; // public static final int URI_CODE = 1; // // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java // public interface QueryContactsUuidsCallback { // // void onComplete(@NonNull final Set<String> uuids); // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Contact.java // public final class Contact { // // @NonNull // private final String name; // // @NonNull // private final String uuid; // // public Contact(@NonNull final String name, @NonNull final String uuid) { // this.name = name; // this.uuid = uuid; // } // // @NonNull // public String getName() { // return name; // } // // @NonNull // public String getUuid() { // return uuid; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Message.java // public final class Message { // // @NonNull // private final String senderUuid; // // @NonNull // private final String messageText; // // private final long receivedTime; // // public Message(@NonNull final String senderUuid, // @NonNull final String messageText, // final long receivedTime) { // this.senderUuid = senderUuid; // this.messageText = messageText; // this.receivedTime = receivedTime; // } // // @NonNull // public String getSenderUuid() { // return senderUuid; // } // // @NonNull // public String getMessageText() { // return messageText; // } // // public long getReceivedTime() { // return receivedTime; // } // } // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java import org.onepf.pushchat.model.db.Message; import java.util.HashSet; import java.util.Set; import android.content.AsyncQueryHandler; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.support.annotation.NonNull; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract.MessageEntry; import org.onepf.pushchat.db.DatabaseHelper.ContactsUuidsAsyncQueryHandler.QueryContactsUuidsCallback; import org.onepf.pushchat.model.db.Contact; null, ContactsContract.TABLE_URI, new String[]{ContactEntry.NAME}, ContactEntry.UUID + "=?", new String[]{message.getSenderUuid()}, null ); } private QueryContactNameQueryHandler.QueryContactNameCallback queryContactNameCallback( @NonNull final Message message ) { return new QueryContactNameQueryHandler.QueryContactNameCallback() { @Override public void onComplete(@NonNull final String name) { final ContentValues contentValues = new ContentValues(); contentValues.put(MessageEntry.SENDER_UUID, message.getSenderUuid()); contentValues.put(MessageEntry.SENDER_NAME, name); contentValues.put(MessageEntry.MESSAGE, message.getMessageText()); contentValues.put(MessageEntry.RECEIVED_TIME, message.getReceivedTime()); asyncQueryHandler.startInsert(MESSAGE_OPERATION_TOKEN, null, MessagesContract.TABLE_URI, contentValues); } }; } public void deleteMessages() { asyncQueryHandler.startDelete(MESSAGE_OPERATION_TOKEN, null, MessagesContract.TABLE_URI, null, null); }
public void addContact(@NonNull final Contact contact) {
onepf/OPFPush
samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactsContract { // public static final String TABLE_NAME = "contacts"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 2; // public static final int URI_CODE = 3; // // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessagesContract { // public static final String TABLE_NAME = "messages"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 0; // public static final int URI_CODE = 1; // // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java // public interface QueryContactsUuidsCallback { // // void onComplete(@NonNull final Set<String> uuids); // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Contact.java // public final class Contact { // // @NonNull // private final String name; // // @NonNull // private final String uuid; // // public Contact(@NonNull final String name, @NonNull final String uuid) { // this.name = name; // this.uuid = uuid; // } // // @NonNull // public String getName() { // return name; // } // // @NonNull // public String getUuid() { // return uuid; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Message.java // public final class Message { // // @NonNull // private final String senderUuid; // // @NonNull // private final String messageText; // // private final long receivedTime; // // public Message(@NonNull final String senderUuid, // @NonNull final String messageText, // final long receivedTime) { // this.senderUuid = senderUuid; // this.messageText = messageText; // this.receivedTime = receivedTime; // } // // @NonNull // public String getSenderUuid() { // return senderUuid; // } // // @NonNull // public String getMessageText() { // return messageText; // } // // public long getReceivedTime() { // return receivedTime; // } // }
import org.onepf.pushchat.model.db.Message; import java.util.HashSet; import java.util.Set; import android.content.AsyncQueryHandler; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.support.annotation.NonNull; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract.MessageEntry; import org.onepf.pushchat.db.DatabaseHelper.ContactsUuidsAsyncQueryHandler.QueryContactsUuidsCallback; import org.onepf.pushchat.model.db.Contact;
final String contactUuid = contact.getUuid(); final ContentValues contactContentValues = new ContentValues(); contactContentValues.put(ContactEntry.NAME, contactName); contactContentValues.put(ContactEntry.UUID, contactUuid); asyncQueryHandler.startInsert(CONTACT_OPERATION_TOKEN, null, ContactsContract.TABLE_URI, contactContentValues); final ContentValues messageContentValues = new ContentValues(); messageContentValues.put(MessageEntry.SENDER_NAME, contactName); asyncQueryHandler.startUpdate( MESSAGE_OPERATION_TOKEN, null, MessagesContract.TABLE_URI, messageContentValues, MessageEntry.SENDER_UUID + "=?", new String[]{contactUuid} ); } public void deleteContact(final long id) { asyncQueryHandler.startDelete( CONTACT_OPERATION_TOKEN, null, ContactsContract.TABLE_URI, ContactEntry.ID + "=?", new String[]{String.valueOf(id)} ); }
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactsContract { // public static final String TABLE_NAME = "contacts"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 2; // public static final int URI_CODE = 3; // // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class ContactEntry { // public static final String ID = BaseColumns._ID; // public static final String UUID = "uuid"; // public static final String NAME = "name"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessagesContract { // public static final String TABLE_NAME = "messages"; // // public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build(); // public static final int ALL_URI_CODE = 0; // public static final int URI_CODE = 1; // // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static class MessageEntry { // public static final String ID = BaseColumns._ID; // public static final String SENDER_UUID = "sender_uuid"; // public static final String SENDER_NAME = "sender_name"; // public static final String MESSAGE = "message"; // public static final String RECEIVED_TIME = "received_time"; // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java // public interface QueryContactsUuidsCallback { // // void onComplete(@NonNull final Set<String> uuids); // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Contact.java // public final class Contact { // // @NonNull // private final String name; // // @NonNull // private final String uuid; // // public Contact(@NonNull final String name, @NonNull final String uuid) { // this.name = name; // this.uuid = uuid; // } // // @NonNull // public String getName() { // return name; // } // // @NonNull // public String getUuid() { // return uuid; // } // } // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Message.java // public final class Message { // // @NonNull // private final String senderUuid; // // @NonNull // private final String messageText; // // private final long receivedTime; // // public Message(@NonNull final String senderUuid, // @NonNull final String messageText, // final long receivedTime) { // this.senderUuid = senderUuid; // this.messageText = messageText; // this.receivedTime = receivedTime; // } // // @NonNull // public String getSenderUuid() { // return senderUuid; // } // // @NonNull // public String getMessageText() { // return messageText; // } // // public long getReceivedTime() { // return receivedTime; // } // } // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java import org.onepf.pushchat.model.db.Message; import java.util.HashSet; import java.util.Set; import android.content.AsyncQueryHandler; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.support.annotation.NonNull; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract; import org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract; import org.onepf.pushchat.db.ContentDescriptor.MessagesContract.MessageEntry; import org.onepf.pushchat.db.DatabaseHelper.ContactsUuidsAsyncQueryHandler.QueryContactsUuidsCallback; import org.onepf.pushchat.model.db.Contact; final String contactUuid = contact.getUuid(); final ContentValues contactContentValues = new ContentValues(); contactContentValues.put(ContactEntry.NAME, contactName); contactContentValues.put(ContactEntry.UUID, contactUuid); asyncQueryHandler.startInsert(CONTACT_OPERATION_TOKEN, null, ContactsContract.TABLE_URI, contactContentValues); final ContentValues messageContentValues = new ContentValues(); messageContentValues.put(MessageEntry.SENDER_NAME, contactName); asyncQueryHandler.startUpdate( MESSAGE_OPERATION_TOKEN, null, MessagesContract.TABLE_URI, messageContentValues, MessageEntry.SENDER_UUID + "=?", new String[]{contactUuid} ); } public void deleteContact(final long id) { asyncQueryHandler.startDelete( CONTACT_OPERATION_TOKEN, null, ContactsContract.TABLE_URI, ContactEntry.ID + "=?", new String[]{String.valueOf(id)} ); }
public void queryAllContactsUuids(@NonNull final QueryContactsUuidsCallback callback) {
onepf/OPFPush
opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/LoginAccountsChangedReceiver.java
// Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/ADMConstants.java // static final String ACCOUNT_TYPE = "com.amazon.account"; // // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/ADMConstants.java // public static final String PROVIDER_NAME = "Amazon Device Messaging";
import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.adm.ADMConstants.ACCOUNT_TYPE; import static org.onepf.opfpush.adm.ADMConstants.PROVIDER_NAME; import android.accounts.Account; import android.accounts.AccountManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFUtils; import static android.Manifest.permission.GET_ACCOUNTS; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.adm; /** * It's used to retry the unregister operation if there was an * {@link com.amazon.device.messaging.ADMConstants#ERROR_AUTHENTICATION_FAILED} error while unregistering. * * @author Roman Savin * @since 03.02.2015 */ public class LoginAccountsChangedReceiver extends BroadcastReceiver { @Override public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { OPFLog.logMethod(context, OPFUtils.toString(intent)); if (!OPFChecks.hasPermission(context, GET_ACCOUNTS)) { OPFLog.w(GET_ACCOUNTS + " permission hasn't been declared"); return; } final PreferencesProvider preferencesProvider = PreferencesProvider.getInstance(context);
// Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/ADMConstants.java // static final String ACCOUNT_TYPE = "com.amazon.account"; // // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/ADMConstants.java // public static final String PROVIDER_NAME = "Amazon Device Messaging"; // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/LoginAccountsChangedReceiver.java import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.adm.ADMConstants.ACCOUNT_TYPE; import static org.onepf.opfpush.adm.ADMConstants.PROVIDER_NAME; import android.accounts.Account; import android.accounts.AccountManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFUtils; import static android.Manifest.permission.GET_ACCOUNTS; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.adm; /** * It's used to retry the unregister operation if there was an * {@link com.amazon.device.messaging.ADMConstants#ERROR_AUTHENTICATION_FAILED} error while unregistering. * * @author Roman Savin * @since 03.02.2015 */ public class LoginAccountsChangedReceiver extends BroadcastReceiver { @Override public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { OPFLog.logMethod(context, OPFUtils.toString(intent)); if (!OPFChecks.hasPermission(context, GET_ACCOUNTS)) { OPFLog.w(GET_ACCOUNTS + " permission hasn't been declared"); return; } final PreferencesProvider preferencesProvider = PreferencesProvider.getInstance(context);
final Account[] amazonAccounts = AccountManager.get(context).getAccountsByType(ACCOUNT_TYPE);
onepf/OPFPush
opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/LoginAccountsChangedReceiver.java
// Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/ADMConstants.java // static final String ACCOUNT_TYPE = "com.amazon.account"; // // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/ADMConstants.java // public static final String PROVIDER_NAME = "Amazon Device Messaging";
import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.adm.ADMConstants.ACCOUNT_TYPE; import static org.onepf.opfpush.adm.ADMConstants.PROVIDER_NAME; import android.accounts.Account; import android.accounts.AccountManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFUtils; import static android.Manifest.permission.GET_ACCOUNTS; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.adm; /** * It's used to retry the unregister operation if there was an * {@link com.amazon.device.messaging.ADMConstants#ERROR_AUTHENTICATION_FAILED} error while unregistering. * * @author Roman Savin * @since 03.02.2015 */ public class LoginAccountsChangedReceiver extends BroadcastReceiver { @Override public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { OPFLog.logMethod(context, OPFUtils.toString(intent)); if (!OPFChecks.hasPermission(context, GET_ACCOUNTS)) { OPFLog.w(GET_ACCOUNTS + " permission hasn't been declared"); return; } final PreferencesProvider preferencesProvider = PreferencesProvider.getInstance(context); final Account[] amazonAccounts = AccountManager.get(context).getAccountsByType(ACCOUNT_TYPE); if (amazonAccounts.length != 0 && preferencesProvider.isAuthenticationFailed()) { OPFLog.d("Retry unregister"); preferencesProvider.removeAuthenticationFailedFlag();
// Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/ADMConstants.java // static final String ACCOUNT_TYPE = "com.amazon.account"; // // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/ADMConstants.java // public static final String PROVIDER_NAME = "Amazon Device Messaging"; // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/LoginAccountsChangedReceiver.java import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.adm.ADMConstants.ACCOUNT_TYPE; import static org.onepf.opfpush.adm.ADMConstants.PROVIDER_NAME; import android.accounts.Account; import android.accounts.AccountManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFUtils; import static android.Manifest.permission.GET_ACCOUNTS; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.adm; /** * It's used to retry the unregister operation if there was an * {@link com.amazon.device.messaging.ADMConstants#ERROR_AUTHENTICATION_FAILED} error while unregistering. * * @author Roman Savin * @since 03.02.2015 */ public class LoginAccountsChangedReceiver extends BroadcastReceiver { @Override public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { OPFLog.logMethod(context, OPFUtils.toString(intent)); if (!OPFChecks.hasPermission(context, GET_ACCOUNTS)) { OPFLog.w(GET_ACCOUNTS + " permission hasn't been declared"); return; } final PreferencesProvider preferencesProvider = PreferencesProvider.getInstance(context); final Account[] amazonAccounts = AccountManager.get(context).getAccountsByType(ACCOUNT_TYPE); if (amazonAccounts.length != 0 && preferencesProvider.isAuthenticationFailed()) { OPFLog.d("Retry unregister"); preferencesProvider.removeAuthenticationFailedFlag();
final Intent retryUnregisterIntent = new Intent(context, RetryBroadcastReceiver.class);
onepf/OPFPush
opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/LoginAccountsChangedReceiver.java
// Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/ADMConstants.java // static final String ACCOUNT_TYPE = "com.amazon.account"; // // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/ADMConstants.java // public static final String PROVIDER_NAME = "Amazon Device Messaging";
import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.adm.ADMConstants.ACCOUNT_TYPE; import static org.onepf.opfpush.adm.ADMConstants.PROVIDER_NAME; import android.accounts.Account; import android.accounts.AccountManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFUtils; import static android.Manifest.permission.GET_ACCOUNTS; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.adm; /** * It's used to retry the unregister operation if there was an * {@link com.amazon.device.messaging.ADMConstants#ERROR_AUTHENTICATION_FAILED} error while unregistering. * * @author Roman Savin * @since 03.02.2015 */ public class LoginAccountsChangedReceiver extends BroadcastReceiver { @Override public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { OPFLog.logMethod(context, OPFUtils.toString(intent)); if (!OPFChecks.hasPermission(context, GET_ACCOUNTS)) { OPFLog.w(GET_ACCOUNTS + " permission hasn't been declared"); return; } final PreferencesProvider preferencesProvider = PreferencesProvider.getInstance(context); final Account[] amazonAccounts = AccountManager.get(context).getAccountsByType(ACCOUNT_TYPE); if (amazonAccounts.length != 0 && preferencesProvider.isAuthenticationFailed()) { OPFLog.d("Retry unregister"); preferencesProvider.removeAuthenticationFailedFlag(); final Intent retryUnregisterIntent = new Intent(context, RetryBroadcastReceiver.class);
// Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/ADMConstants.java // static final String ACCOUNT_TYPE = "com.amazon.account"; // // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/ADMConstants.java // public static final String PROVIDER_NAME = "Amazon Device Messaging"; // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/LoginAccountsChangedReceiver.java import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.adm.ADMConstants.ACCOUNT_TYPE; import static org.onepf.opfpush.adm.ADMConstants.PROVIDER_NAME; import android.accounts.Account; import android.accounts.AccountManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFUtils; import static android.Manifest.permission.GET_ACCOUNTS; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.adm; /** * It's used to retry the unregister operation if there was an * {@link com.amazon.device.messaging.ADMConstants#ERROR_AUTHENTICATION_FAILED} error while unregistering. * * @author Roman Savin * @since 03.02.2015 */ public class LoginAccountsChangedReceiver extends BroadcastReceiver { @Override public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { OPFLog.logMethod(context, OPFUtils.toString(intent)); if (!OPFChecks.hasPermission(context, GET_ACCOUNTS)) { OPFLog.w(GET_ACCOUNTS + " permission hasn't been declared"); return; } final PreferencesProvider preferencesProvider = PreferencesProvider.getInstance(context); final Account[] amazonAccounts = AccountManager.get(context).getAccountsByType(ACCOUNT_TYPE); if (amazonAccounts.length != 0 && preferencesProvider.isAuthenticationFailed()) { OPFLog.d("Retry unregister"); preferencesProvider.removeAuthenticationFailedFlag(); final Intent retryUnregisterIntent = new Intent(context, RetryBroadcastReceiver.class);
retryUnregisterIntent.setAction(ACTION_RETRY_UNREGISTER);
onepf/OPFPush
opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/LoginAccountsChangedReceiver.java
// Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/ADMConstants.java // static final String ACCOUNT_TYPE = "com.amazon.account"; // // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/ADMConstants.java // public static final String PROVIDER_NAME = "Amazon Device Messaging";
import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.adm.ADMConstants.ACCOUNT_TYPE; import static org.onepf.opfpush.adm.ADMConstants.PROVIDER_NAME; import android.accounts.Account; import android.accounts.AccountManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFUtils; import static android.Manifest.permission.GET_ACCOUNTS; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.adm; /** * It's used to retry the unregister operation if there was an * {@link com.amazon.device.messaging.ADMConstants#ERROR_AUTHENTICATION_FAILED} error while unregistering. * * @author Roman Savin * @since 03.02.2015 */ public class LoginAccountsChangedReceiver extends BroadcastReceiver { @Override public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { OPFLog.logMethod(context, OPFUtils.toString(intent)); if (!OPFChecks.hasPermission(context, GET_ACCOUNTS)) { OPFLog.w(GET_ACCOUNTS + " permission hasn't been declared"); return; } final PreferencesProvider preferencesProvider = PreferencesProvider.getInstance(context); final Account[] amazonAccounts = AccountManager.get(context).getAccountsByType(ACCOUNT_TYPE); if (amazonAccounts.length != 0 && preferencesProvider.isAuthenticationFailed()) { OPFLog.d("Retry unregister"); preferencesProvider.removeAuthenticationFailedFlag(); final Intent retryUnregisterIntent = new Intent(context, RetryBroadcastReceiver.class); retryUnregisterIntent.setAction(ACTION_RETRY_UNREGISTER);
// Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/ADMConstants.java // static final String ACCOUNT_TYPE = "com.amazon.account"; // // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/ADMConstants.java // public static final String PROVIDER_NAME = "Amazon Device Messaging"; // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/LoginAccountsChangedReceiver.java import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.adm.ADMConstants.ACCOUNT_TYPE; import static org.onepf.opfpush.adm.ADMConstants.PROVIDER_NAME; import android.accounts.Account; import android.accounts.AccountManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFUtils; import static android.Manifest.permission.GET_ACCOUNTS; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.adm; /** * It's used to retry the unregister operation if there was an * {@link com.amazon.device.messaging.ADMConstants#ERROR_AUTHENTICATION_FAILED} error while unregistering. * * @author Roman Savin * @since 03.02.2015 */ public class LoginAccountsChangedReceiver extends BroadcastReceiver { @Override public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { OPFLog.logMethod(context, OPFUtils.toString(intent)); if (!OPFChecks.hasPermission(context, GET_ACCOUNTS)) { OPFLog.w(GET_ACCOUNTS + " permission hasn't been declared"); return; } final PreferencesProvider preferencesProvider = PreferencesProvider.getInstance(context); final Account[] amazonAccounts = AccountManager.get(context).getAccountsByType(ACCOUNT_TYPE); if (amazonAccounts.length != 0 && preferencesProvider.isAuthenticationFailed()) { OPFLog.d("Retry unregister"); preferencesProvider.removeAuthenticationFailedFlag(); final Intent retryUnregisterIntent = new Intent(context, RetryBroadcastReceiver.class); retryUnregisterIntent.setAction(ACTION_RETRY_UNREGISTER);
retryUnregisterIntent.putExtra(EXTRA_PROVIDER_NAME, PROVIDER_NAME);
onepf/OPFPush
opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/LoginAccountsChangedReceiver.java
// Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/ADMConstants.java // static final String ACCOUNT_TYPE = "com.amazon.account"; // // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/ADMConstants.java // public static final String PROVIDER_NAME = "Amazon Device Messaging";
import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.adm.ADMConstants.ACCOUNT_TYPE; import static org.onepf.opfpush.adm.ADMConstants.PROVIDER_NAME; import android.accounts.Account; import android.accounts.AccountManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFUtils; import static android.Manifest.permission.GET_ACCOUNTS; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.adm; /** * It's used to retry the unregister operation if there was an * {@link com.amazon.device.messaging.ADMConstants#ERROR_AUTHENTICATION_FAILED} error while unregistering. * * @author Roman Savin * @since 03.02.2015 */ public class LoginAccountsChangedReceiver extends BroadcastReceiver { @Override public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { OPFLog.logMethod(context, OPFUtils.toString(intent)); if (!OPFChecks.hasPermission(context, GET_ACCOUNTS)) { OPFLog.w(GET_ACCOUNTS + " permission hasn't been declared"); return; } final PreferencesProvider preferencesProvider = PreferencesProvider.getInstance(context); final Account[] amazonAccounts = AccountManager.get(context).getAccountsByType(ACCOUNT_TYPE); if (amazonAccounts.length != 0 && preferencesProvider.isAuthenticationFailed()) { OPFLog.d("Retry unregister"); preferencesProvider.removeAuthenticationFailedFlag(); final Intent retryUnregisterIntent = new Intent(context, RetryBroadcastReceiver.class); retryUnregisterIntent.setAction(ACTION_RETRY_UNREGISTER);
// Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/ADMConstants.java // static final String ACCOUNT_TYPE = "com.amazon.account"; // // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/ADMConstants.java // public static final String PROVIDER_NAME = "Amazon Device Messaging"; // Path: opfpush-providers/adm/src/main/java/org/onepf/opfpush/adm/LoginAccountsChangedReceiver.java import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.adm.ADMConstants.ACCOUNT_TYPE; import static org.onepf.opfpush.adm.ADMConstants.PROVIDER_NAME; import android.accounts.Account; import android.accounts.AccountManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFUtils; import static android.Manifest.permission.GET_ACCOUNTS; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.adm; /** * It's used to retry the unregister operation if there was an * {@link com.amazon.device.messaging.ADMConstants#ERROR_AUTHENTICATION_FAILED} error while unregistering. * * @author Roman Savin * @since 03.02.2015 */ public class LoginAccountsChangedReceiver extends BroadcastReceiver { @Override public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { OPFLog.logMethod(context, OPFUtils.toString(intent)); if (!OPFChecks.hasPermission(context, GET_ACCOUNTS)) { OPFLog.w(GET_ACCOUNTS + " permission hasn't been declared"); return; } final PreferencesProvider preferencesProvider = PreferencesProvider.getInstance(context); final Account[] amazonAccounts = AccountManager.get(context).getAccountsByType(ACCOUNT_TYPE); if (amazonAccounts.length != 0 && preferencesProvider.isAuthenticationFailed()) { OPFLog.d("Retry unregister"); preferencesProvider.removeAuthenticationFailedFlag(); final Intent retryUnregisterIntent = new Intent(context, RetryBroadcastReceiver.class); retryUnregisterIntent.setAction(ACTION_RETRY_UNREGISTER);
retryUnregisterIntent.putExtra(EXTRA_PROVIDER_NAME, PROVIDER_NAME);
onepf/OPFPush
opfpush/src/main/java/org/onepf/opfpush/RegisteringTimeoutController.java
// Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // static final String ACTION_CHECK_REGISTERING_TIMEOUT = BuildConfig.APPLICATION_ID + "intent.CHECK_REGISTERING_TIMEOUT"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME";
import static org.onepf.opfpush.OPFConstants.ACTION_CHECK_REGISTERING_TIMEOUT; import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfutils.OPFLog; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.concurrent.TimeUnit;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush; /** * @author Roman Savin * @since 18.02.2015 */ final class RegisteringTimeoutController { private static final long TIMEOUT_MINUTES = 5; private RegisteringTimeoutController() { throw new UnsupportedOperationException(); } static void setTimeout(@NonNull final Context context, @NonNull final String providerName) { OPFLog.logMethod(context, providerName); final long when = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(TIMEOUT_MINUTES); OPFLog.d( "Set registering timeout : %s", SimpleDateFormat.getDateTimeInstance( DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.US ).format(new Date(when)) ); final AlarmManager alarmManager = (AlarmManager) context .getSystemService(Context.ALARM_SERVICE); final Intent intent = new Intent(context, RetryBroadcastReceiver.class);
// Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // static final String ACTION_CHECK_REGISTERING_TIMEOUT = BuildConfig.APPLICATION_ID + "intent.CHECK_REGISTERING_TIMEOUT"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // Path: opfpush/src/main/java/org/onepf/opfpush/RegisteringTimeoutController.java import static org.onepf.opfpush.OPFConstants.ACTION_CHECK_REGISTERING_TIMEOUT; import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfutils.OPFLog; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.concurrent.TimeUnit; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush; /** * @author Roman Savin * @since 18.02.2015 */ final class RegisteringTimeoutController { private static final long TIMEOUT_MINUTES = 5; private RegisteringTimeoutController() { throw new UnsupportedOperationException(); } static void setTimeout(@NonNull final Context context, @NonNull final String providerName) { OPFLog.logMethod(context, providerName); final long when = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(TIMEOUT_MINUTES); OPFLog.d( "Set registering timeout : %s", SimpleDateFormat.getDateTimeInstance( DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.US ).format(new Date(when)) ); final AlarmManager alarmManager = (AlarmManager) context .getSystemService(Context.ALARM_SERVICE); final Intent intent = new Intent(context, RetryBroadcastReceiver.class);
intent.setAction(ACTION_CHECK_REGISTERING_TIMEOUT);
onepf/OPFPush
opfpush/src/main/java/org/onepf/opfpush/RegisteringTimeoutController.java
// Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // static final String ACTION_CHECK_REGISTERING_TIMEOUT = BuildConfig.APPLICATION_ID + "intent.CHECK_REGISTERING_TIMEOUT"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME";
import static org.onepf.opfpush.OPFConstants.ACTION_CHECK_REGISTERING_TIMEOUT; import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfutils.OPFLog; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.concurrent.TimeUnit;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush; /** * @author Roman Savin * @since 18.02.2015 */ final class RegisteringTimeoutController { private static final long TIMEOUT_MINUTES = 5; private RegisteringTimeoutController() { throw new UnsupportedOperationException(); } static void setTimeout(@NonNull final Context context, @NonNull final String providerName) { OPFLog.logMethod(context, providerName); final long when = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(TIMEOUT_MINUTES); OPFLog.d( "Set registering timeout : %s", SimpleDateFormat.getDateTimeInstance( DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.US ).format(new Date(when)) ); final AlarmManager alarmManager = (AlarmManager) context .getSystemService(Context.ALARM_SERVICE); final Intent intent = new Intent(context, RetryBroadcastReceiver.class); intent.setAction(ACTION_CHECK_REGISTERING_TIMEOUT);
// Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // static final String ACTION_CHECK_REGISTERING_TIMEOUT = BuildConfig.APPLICATION_ID + "intent.CHECK_REGISTERING_TIMEOUT"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // Path: opfpush/src/main/java/org/onepf/opfpush/RegisteringTimeoutController.java import static org.onepf.opfpush.OPFConstants.ACTION_CHECK_REGISTERING_TIMEOUT; import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfutils.OPFLog; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.concurrent.TimeUnit; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush; /** * @author Roman Savin * @since 18.02.2015 */ final class RegisteringTimeoutController { private static final long TIMEOUT_MINUTES = 5; private RegisteringTimeoutController() { throw new UnsupportedOperationException(); } static void setTimeout(@NonNull final Context context, @NonNull final String providerName) { OPFLog.logMethod(context, providerName); final long when = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(TIMEOUT_MINUTES); OPFLog.d( "Set registering timeout : %s", SimpleDateFormat.getDateTimeInstance( DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.US ).format(new Date(when)) ); final AlarmManager alarmManager = (AlarmManager) context .getSystemService(Context.ALARM_SERVICE); final Intent intent = new Intent(context, RetryBroadcastReceiver.class); intent.setAction(ACTION_CHECK_REGISTERING_TIMEOUT);
intent.putExtra(EXTRA_PROVIDER_NAME, providerName);
onepf/OPFPush
opfpush/src/main/java/org/onepf/opfpush/backoff/RetryManager.java
// Path: opfpush/src/main/java/org/onepf/opfpush/ConnectivityChangeReceiver.java // public final class ConnectivityChangeReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final Set<Pair<String, String>> retryProvidersActions = RetryManager.getInstance() // .getRetryProvidersActions(); // // final OPFPushHelper helper = OPFPush.getHelper(); // for (Pair<String, String> retryProviderAction : retryProvidersActions) { // final String providerName = retryProviderAction.first; // final String action = retryProviderAction.second; // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // } // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java // public enum Operation { // REGISTER, // UNREGISTER // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME";
import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Pair; import org.onepf.opfpush.ConnectivityChangeReceiver; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfpush.model.Operation; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.exception.InitException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashSet; import java.util.Locale; import java.util.Set; import static android.content.Context.ALARM_SERVICE; import static android.net.ConnectivityManager.CONNECTIVITY_ACTION; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.model.Operation.REGISTER; import static org.onepf.opfpush.model.Operation.UNREGISTER;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.backoff; /** * @author Roman Savin * @since 06.02.2015 */ public final class RetryManager implements BackoffManager { private static volatile RetryManager instance; @NonNull private final Context appContext; @NonNull private final BackoffManager backoffManager; @NonNull private final AlarmManager alarmManager; private final Set<Pair<String, String>> retryProvidersActions; @Nullable
// Path: opfpush/src/main/java/org/onepf/opfpush/ConnectivityChangeReceiver.java // public final class ConnectivityChangeReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final Set<Pair<String, String>> retryProvidersActions = RetryManager.getInstance() // .getRetryProvidersActions(); // // final OPFPushHelper helper = OPFPush.getHelper(); // for (Pair<String, String> retryProviderAction : retryProvidersActions) { // final String providerName = retryProviderAction.first; // final String action = retryProviderAction.second; // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // } // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java // public enum Operation { // REGISTER, // UNREGISTER // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // Path: opfpush/src/main/java/org/onepf/opfpush/backoff/RetryManager.java import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Pair; import org.onepf.opfpush.ConnectivityChangeReceiver; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfpush.model.Operation; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.exception.InitException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashSet; import java.util.Locale; import java.util.Set; import static android.content.Context.ALARM_SERVICE; import static android.net.ConnectivityManager.CONNECTIVITY_ACTION; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.model.Operation.REGISTER; import static org.onepf.opfpush.model.Operation.UNREGISTER; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.backoff; /** * @author Roman Savin * @since 06.02.2015 */ public final class RetryManager implements BackoffManager { private static volatile RetryManager instance; @NonNull private final Context appContext; @NonNull private final BackoffManager backoffManager; @NonNull private final AlarmManager alarmManager; private final Set<Pair<String, String>> retryProvidersActions; @Nullable
private ConnectivityChangeReceiver connectivityChangeReceiver;
onepf/OPFPush
opfpush/src/main/java/org/onepf/opfpush/backoff/RetryManager.java
// Path: opfpush/src/main/java/org/onepf/opfpush/ConnectivityChangeReceiver.java // public final class ConnectivityChangeReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final Set<Pair<String, String>> retryProvidersActions = RetryManager.getInstance() // .getRetryProvidersActions(); // // final OPFPushHelper helper = OPFPush.getHelper(); // for (Pair<String, String> retryProviderAction : retryProvidersActions) { // final String providerName = retryProviderAction.first; // final String action = retryProviderAction.second; // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // } // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java // public enum Operation { // REGISTER, // UNREGISTER // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME";
import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Pair; import org.onepf.opfpush.ConnectivityChangeReceiver; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfpush.model.Operation; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.exception.InitException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashSet; import java.util.Locale; import java.util.Set; import static android.content.Context.ALARM_SERVICE; import static android.net.ConnectivityManager.CONNECTIVITY_ACTION; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.model.Operation.REGISTER; import static org.onepf.opfpush.model.Operation.UNREGISTER;
this.backoffManager = backoffManager; this.alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE); this.retryProvidersActions = new HashSet<>(); } @NonNull @SuppressWarnings("PMD.NonThreadSafeSingleton") public static RetryManager init(@NonNull final Context context, @NonNull final BackoffManager backoffManager) { OPFChecks.checkThread(true); checkInit(false); return instance = new RetryManager(context, backoffManager); } @NonNull public static RetryManager getInstance() { OPFChecks.checkThread(true); checkInit(true); return instance; } private static void checkInit(final boolean initExpected) { final boolean isInit = instance != null; if (initExpected != isInit) { throw new InitException(isInit); } } @Override public boolean hasTries(@NonNull final String providerName,
// Path: opfpush/src/main/java/org/onepf/opfpush/ConnectivityChangeReceiver.java // public final class ConnectivityChangeReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final Set<Pair<String, String>> retryProvidersActions = RetryManager.getInstance() // .getRetryProvidersActions(); // // final OPFPushHelper helper = OPFPush.getHelper(); // for (Pair<String, String> retryProviderAction : retryProvidersActions) { // final String providerName = retryProviderAction.first; // final String action = retryProviderAction.second; // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // } // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java // public enum Operation { // REGISTER, // UNREGISTER // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // Path: opfpush/src/main/java/org/onepf/opfpush/backoff/RetryManager.java import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Pair; import org.onepf.opfpush.ConnectivityChangeReceiver; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfpush.model.Operation; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.exception.InitException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashSet; import java.util.Locale; import java.util.Set; import static android.content.Context.ALARM_SERVICE; import static android.net.ConnectivityManager.CONNECTIVITY_ACTION; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.model.Operation.REGISTER; import static org.onepf.opfpush.model.Operation.UNREGISTER; this.backoffManager = backoffManager; this.alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE); this.retryProvidersActions = new HashSet<>(); } @NonNull @SuppressWarnings("PMD.NonThreadSafeSingleton") public static RetryManager init(@NonNull final Context context, @NonNull final BackoffManager backoffManager) { OPFChecks.checkThread(true); checkInit(false); return instance = new RetryManager(context, backoffManager); } @NonNull public static RetryManager getInstance() { OPFChecks.checkThread(true); checkInit(true); return instance; } private static void checkInit(final boolean initExpected) { final boolean isInit = instance != null; if (initExpected != isInit) { throw new InitException(isInit); } } @Override public boolean hasTries(@NonNull final String providerName,
@NonNull final Operation operation) {
onepf/OPFPush
opfpush/src/main/java/org/onepf/opfpush/backoff/RetryManager.java
// Path: opfpush/src/main/java/org/onepf/opfpush/ConnectivityChangeReceiver.java // public final class ConnectivityChangeReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final Set<Pair<String, String>> retryProvidersActions = RetryManager.getInstance() // .getRetryProvidersActions(); // // final OPFPushHelper helper = OPFPush.getHelper(); // for (Pair<String, String> retryProviderAction : retryProvidersActions) { // final String providerName = retryProviderAction.first; // final String action = retryProviderAction.second; // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // } // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java // public enum Operation { // REGISTER, // UNREGISTER // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME";
import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Pair; import org.onepf.opfpush.ConnectivityChangeReceiver; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfpush.model.Operation; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.exception.InitException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashSet; import java.util.Locale; import java.util.Set; import static android.content.Context.ALARM_SERVICE; import static android.net.ConnectivityManager.CONNECTIVITY_ACTION; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.model.Operation.REGISTER; import static org.onepf.opfpush.model.Operation.UNREGISTER;
checkInit(true); return instance; } private static void checkInit(final boolean initExpected) { final boolean isInit = instance != null; if (initExpected != isInit) { throw new InitException(isInit); } } @Override public boolean hasTries(@NonNull final String providerName, @NonNull final Operation operation) { return backoffManager.hasTries(providerName, operation); } @Override public long getTryDelay(@NonNull final String providerName, @NonNull final Operation operation) { return backoffManager.getTryDelay(providerName, operation); } @Override public void reset(@NonNull final String providerName, @NonNull final Operation operation) { backoffManager.reset(providerName, operation); } public void postRetryRegister(@NonNull final String providerName) { OPFLog.logMethod(providerName);
// Path: opfpush/src/main/java/org/onepf/opfpush/ConnectivityChangeReceiver.java // public final class ConnectivityChangeReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final Set<Pair<String, String>> retryProvidersActions = RetryManager.getInstance() // .getRetryProvidersActions(); // // final OPFPushHelper helper = OPFPush.getHelper(); // for (Pair<String, String> retryProviderAction : retryProvidersActions) { // final String providerName = retryProviderAction.first; // final String action = retryProviderAction.second; // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // } // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java // public enum Operation { // REGISTER, // UNREGISTER // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // Path: opfpush/src/main/java/org/onepf/opfpush/backoff/RetryManager.java import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Pair; import org.onepf.opfpush.ConnectivityChangeReceiver; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfpush.model.Operation; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.exception.InitException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashSet; import java.util.Locale; import java.util.Set; import static android.content.Context.ALARM_SERVICE; import static android.net.ConnectivityManager.CONNECTIVITY_ACTION; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.model.Operation.REGISTER; import static org.onepf.opfpush.model.Operation.UNREGISTER; checkInit(true); return instance; } private static void checkInit(final boolean initExpected) { final boolean isInit = instance != null; if (initExpected != isInit) { throw new InitException(isInit); } } @Override public boolean hasTries(@NonNull final String providerName, @NonNull final Operation operation) { return backoffManager.hasTries(providerName, operation); } @Override public long getTryDelay(@NonNull final String providerName, @NonNull final Operation operation) { return backoffManager.getTryDelay(providerName, operation); } @Override public void reset(@NonNull final String providerName, @NonNull final Operation operation) { backoffManager.reset(providerName, operation); } public void postRetryRegister(@NonNull final String providerName) { OPFLog.logMethod(providerName);
postRetry(providerName, REGISTER, ACTION_RETRY_REGISTER);
onepf/OPFPush
opfpush/src/main/java/org/onepf/opfpush/backoff/RetryManager.java
// Path: opfpush/src/main/java/org/onepf/opfpush/ConnectivityChangeReceiver.java // public final class ConnectivityChangeReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final Set<Pair<String, String>> retryProvidersActions = RetryManager.getInstance() // .getRetryProvidersActions(); // // final OPFPushHelper helper = OPFPush.getHelper(); // for (Pair<String, String> retryProviderAction : retryProvidersActions) { // final String providerName = retryProviderAction.first; // final String action = retryProviderAction.second; // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // } // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java // public enum Operation { // REGISTER, // UNREGISTER // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME";
import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Pair; import org.onepf.opfpush.ConnectivityChangeReceiver; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfpush.model.Operation; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.exception.InitException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashSet; import java.util.Locale; import java.util.Set; import static android.content.Context.ALARM_SERVICE; import static android.net.ConnectivityManager.CONNECTIVITY_ACTION; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.model.Operation.REGISTER; import static org.onepf.opfpush.model.Operation.UNREGISTER;
final boolean isInit = instance != null; if (initExpected != isInit) { throw new InitException(isInit); } } @Override public boolean hasTries(@NonNull final String providerName, @NonNull final Operation operation) { return backoffManager.hasTries(providerName, operation); } @Override public long getTryDelay(@NonNull final String providerName, @NonNull final Operation operation) { return backoffManager.getTryDelay(providerName, operation); } @Override public void reset(@NonNull final String providerName, @NonNull final Operation operation) { backoffManager.reset(providerName, operation); } public void postRetryRegister(@NonNull final String providerName) { OPFLog.logMethod(providerName); postRetry(providerName, REGISTER, ACTION_RETRY_REGISTER); } public void postRetryUnregister(@NonNull final String providerName) { OPFLog.logMethod(providerName);
// Path: opfpush/src/main/java/org/onepf/opfpush/ConnectivityChangeReceiver.java // public final class ConnectivityChangeReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final Set<Pair<String, String>> retryProvidersActions = RetryManager.getInstance() // .getRetryProvidersActions(); // // final OPFPushHelper helper = OPFPush.getHelper(); // for (Pair<String, String> retryProviderAction : retryProvidersActions) { // final String providerName = retryProviderAction.first; // final String action = retryProviderAction.second; // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // } // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java // public enum Operation { // REGISTER, // UNREGISTER // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // Path: opfpush/src/main/java/org/onepf/opfpush/backoff/RetryManager.java import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Pair; import org.onepf.opfpush.ConnectivityChangeReceiver; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfpush.model.Operation; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.exception.InitException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashSet; import java.util.Locale; import java.util.Set; import static android.content.Context.ALARM_SERVICE; import static android.net.ConnectivityManager.CONNECTIVITY_ACTION; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.model.Operation.REGISTER; import static org.onepf.opfpush.model.Operation.UNREGISTER; final boolean isInit = instance != null; if (initExpected != isInit) { throw new InitException(isInit); } } @Override public boolean hasTries(@NonNull final String providerName, @NonNull final Operation operation) { return backoffManager.hasTries(providerName, operation); } @Override public long getTryDelay(@NonNull final String providerName, @NonNull final Operation operation) { return backoffManager.getTryDelay(providerName, operation); } @Override public void reset(@NonNull final String providerName, @NonNull final Operation operation) { backoffManager.reset(providerName, operation); } public void postRetryRegister(@NonNull final String providerName) { OPFLog.logMethod(providerName); postRetry(providerName, REGISTER, ACTION_RETRY_REGISTER); } public void postRetryUnregister(@NonNull final String providerName) { OPFLog.logMethod(providerName);
postRetry(providerName, UNREGISTER, ACTION_RETRY_UNREGISTER);
onepf/OPFPush
opfpush/src/main/java/org/onepf/opfpush/backoff/RetryManager.java
// Path: opfpush/src/main/java/org/onepf/opfpush/ConnectivityChangeReceiver.java // public final class ConnectivityChangeReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final Set<Pair<String, String>> retryProvidersActions = RetryManager.getInstance() // .getRetryProvidersActions(); // // final OPFPushHelper helper = OPFPush.getHelper(); // for (Pair<String, String> retryProviderAction : retryProvidersActions) { // final String providerName = retryProviderAction.first; // final String action = retryProviderAction.second; // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // } // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java // public enum Operation { // REGISTER, // UNREGISTER // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME";
import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Pair; import org.onepf.opfpush.ConnectivityChangeReceiver; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfpush.model.Operation; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.exception.InitException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashSet; import java.util.Locale; import java.util.Set; import static android.content.Context.ALARM_SERVICE; import static android.net.ConnectivityManager.CONNECTIVITY_ACTION; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.model.Operation.REGISTER; import static org.onepf.opfpush.model.Operation.UNREGISTER;
OPFLog.logMethod(providerName); cancelRetry(providerName, REGISTER, ACTION_RETRY_REGISTER); } public void cancelRetryUnregister(@NonNull final String providerName) { OPFLog.logMethod(providerName); cancelRetry(providerName, UNREGISTER, ACTION_RETRY_UNREGISTER); } @NonNull public Set<Pair<String, String>> getRetryProvidersActions() { OPFLog.logMethod(); return retryProvidersActions; } private void postRetry(@NonNull final String providerName, @NonNull final Operation operation, @NonNull final String action) { final long when = System.currentTimeMillis() + getTryDelay(providerName, operation); OPFLog.d("Post retry %s provider '%s' at %s", operation, providerName, SimpleDateFormat.getDateTimeInstance( DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.US ).format(new Date(when)) ); retryProvidersActions.add(new Pair<>(providerName, action)); registerConnectivityChangeReceiver();
// Path: opfpush/src/main/java/org/onepf/opfpush/ConnectivityChangeReceiver.java // public final class ConnectivityChangeReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final Set<Pair<String, String>> retryProvidersActions = RetryManager.getInstance() // .getRetryProvidersActions(); // // final OPFPushHelper helper = OPFPush.getHelper(); // for (Pair<String, String> retryProviderAction : retryProvidersActions) { // final String providerName = retryProviderAction.first; // final String action = retryProviderAction.second; // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // } // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java // public enum Operation { // REGISTER, // UNREGISTER // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // Path: opfpush/src/main/java/org/onepf/opfpush/backoff/RetryManager.java import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Pair; import org.onepf.opfpush.ConnectivityChangeReceiver; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfpush.model.Operation; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.exception.InitException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashSet; import java.util.Locale; import java.util.Set; import static android.content.Context.ALARM_SERVICE; import static android.net.ConnectivityManager.CONNECTIVITY_ACTION; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.model.Operation.REGISTER; import static org.onepf.opfpush.model.Operation.UNREGISTER; OPFLog.logMethod(providerName); cancelRetry(providerName, REGISTER, ACTION_RETRY_REGISTER); } public void cancelRetryUnregister(@NonNull final String providerName) { OPFLog.logMethod(providerName); cancelRetry(providerName, UNREGISTER, ACTION_RETRY_UNREGISTER); } @NonNull public Set<Pair<String, String>> getRetryProvidersActions() { OPFLog.logMethod(); return retryProvidersActions; } private void postRetry(@NonNull final String providerName, @NonNull final Operation operation, @NonNull final String action) { final long when = System.currentTimeMillis() + getTryDelay(providerName, operation); OPFLog.d("Post retry %s provider '%s' at %s", operation, providerName, SimpleDateFormat.getDateTimeInstance( DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.US ).format(new Date(when)) ); retryProvidersActions.add(new Pair<>(providerName, action)); registerConnectivityChangeReceiver();
final Intent intent = new Intent(appContext, RetryBroadcastReceiver.class);
onepf/OPFPush
opfpush/src/main/java/org/onepf/opfpush/backoff/RetryManager.java
// Path: opfpush/src/main/java/org/onepf/opfpush/ConnectivityChangeReceiver.java // public final class ConnectivityChangeReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final Set<Pair<String, String>> retryProvidersActions = RetryManager.getInstance() // .getRetryProvidersActions(); // // final OPFPushHelper helper = OPFPush.getHelper(); // for (Pair<String, String> retryProviderAction : retryProvidersActions) { // final String providerName = retryProviderAction.first; // final String action = retryProviderAction.second; // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // } // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java // public enum Operation { // REGISTER, // UNREGISTER // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME";
import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Pair; import org.onepf.opfpush.ConnectivityChangeReceiver; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfpush.model.Operation; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.exception.InitException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashSet; import java.util.Locale; import java.util.Set; import static android.content.Context.ALARM_SERVICE; import static android.net.ConnectivityManager.CONNECTIVITY_ACTION; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.model.Operation.REGISTER; import static org.onepf.opfpush.model.Operation.UNREGISTER;
} public void cancelRetryUnregister(@NonNull final String providerName) { OPFLog.logMethod(providerName); cancelRetry(providerName, UNREGISTER, ACTION_RETRY_UNREGISTER); } @NonNull public Set<Pair<String, String>> getRetryProvidersActions() { OPFLog.logMethod(); return retryProvidersActions; } private void postRetry(@NonNull final String providerName, @NonNull final Operation operation, @NonNull final String action) { final long when = System.currentTimeMillis() + getTryDelay(providerName, operation); OPFLog.d("Post retry %s provider '%s' at %s", operation, providerName, SimpleDateFormat.getDateTimeInstance( DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.US ).format(new Date(when)) ); retryProvidersActions.add(new Pair<>(providerName, action)); registerConnectivityChangeReceiver(); final Intent intent = new Intent(appContext, RetryBroadcastReceiver.class); intent.setAction(action);
// Path: opfpush/src/main/java/org/onepf/opfpush/ConnectivityChangeReceiver.java // public final class ConnectivityChangeReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final Set<Pair<String, String>> retryProvidersActions = RetryManager.getInstance() // .getRetryProvidersActions(); // // final OPFPushHelper helper = OPFPush.getHelper(); // for (Pair<String, String> retryProviderAction : retryProvidersActions) { // final String providerName = retryProviderAction.first; // final String action = retryProviderAction.second; // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // } // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java // public final class RetryBroadcastReceiver extends BroadcastReceiver { // // @Override // public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { // OPFLog.logMethod(context, OPFUtils.toString(intent)); // // final OPFPushHelper helper = OPFPush.getHelper(); // if (helper.isInitDone()) { // OPFLog.d("Initialisation is done"); // // final String action = intent.getAction(); // final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); // switch (action) { // case ACTION_RETRY_REGISTER: // helper.register(providerName); // break; // case ACTION_RETRY_UNREGISTER: // helper.unregister(providerName); // break; // case ACTION_CHECK_REGISTERING_TIMEOUT: // checkRegistering(context, helper, providerName); // break; // default: // throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); // } // } else { // OPFLog.w("OPFPush must be initialized"); // } // } // // private void checkRegistering(@NonNull final Context context, // @NonNull final OPFPushHelper helper, // @NonNull final String providerName) { // OPFLog.logMethod(context, helper, providerName); // if (helper.isRegistering()) { // Settings.getInstance(context).saveState(State.UNREGISTERED); // helper.registerNextAvailableProvider(providerName); // } // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java // public enum Operation { // REGISTER, // UNREGISTER // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // Path: opfpush/src/main/java/org/onepf/opfpush/backoff/RetryManager.java import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Pair; import org.onepf.opfpush.ConnectivityChangeReceiver; import org.onepf.opfpush.RetryBroadcastReceiver; import org.onepf.opfpush.model.Operation; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.exception.InitException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashSet; import java.util.Locale; import java.util.Set; import static android.content.Context.ALARM_SERVICE; import static android.net.ConnectivityManager.CONNECTIVITY_ACTION; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import static org.onepf.opfpush.model.Operation.REGISTER; import static org.onepf.opfpush.model.Operation.UNREGISTER; } public void cancelRetryUnregister(@NonNull final String providerName) { OPFLog.logMethod(providerName); cancelRetry(providerName, UNREGISTER, ACTION_RETRY_UNREGISTER); } @NonNull public Set<Pair<String, String>> getRetryProvidersActions() { OPFLog.logMethod(); return retryProvidersActions; } private void postRetry(@NonNull final String providerName, @NonNull final Operation operation, @NonNull final String action) { final long when = System.currentTimeMillis() + getTryDelay(providerName, operation); OPFLog.d("Post retry %s provider '%s' at %s", operation, providerName, SimpleDateFormat.getDateTimeInstance( DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.US ).format(new Date(when)) ); retryProvidersActions.add(new Pair<>(providerName, action)); registerConnectivityChangeReceiver(); final Intent intent = new Intent(appContext, RetryBroadcastReceiver.class); intent.setAction(action);
intent.putExtra(EXTRA_PROVIDER_NAME, providerName);
onepf/OPFPush
opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java
// Path: opfpush/src/main/java/org/onepf/opfpush/model/State.java // public enum State { // // /** // * Indicates that an unregistration has been completed. // */ // UNREGISTERED(0), // // /** // * Indicates that a registration has been completed. // */ // REGISTERED(2), // // /** // * Indicates that a registration is being performed. // */ // REGISTERING(3); // // private int value; // // State(int value) { // this.value = value; // } // // public int getValue() { // return value; // } // // @Nullable // public static State fromValue(final int fromValue) { // final State[] values = values(); // for (final State state : values) { // final int stateValue = state.getValue(); // if (stateValue == fromValue) { // return state; // } // } // // return null; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // static final String ACTION_CHECK_REGISTERING_TIMEOUT = BuildConfig.APPLICATION_ID + "intent.CHECK_REGISTERING_TIMEOUT"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME";
import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfpush.model.State; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFUtils; import java.util.Locale; import static org.onepf.opfpush.OPFConstants.ACTION_CHECK_REGISTERING_TIMEOUT; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush; /** * @author Kirill Rozov * @author Roman Savin * @since 01.10.14. */ public final class RetryBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { OPFLog.logMethod(context, OPFUtils.toString(intent)); final OPFPushHelper helper = OPFPush.getHelper(); if (helper.isInitDone()) { OPFLog.d("Initialisation is done"); final String action = intent.getAction();
// Path: opfpush/src/main/java/org/onepf/opfpush/model/State.java // public enum State { // // /** // * Indicates that an unregistration has been completed. // */ // UNREGISTERED(0), // // /** // * Indicates that a registration has been completed. // */ // REGISTERED(2), // // /** // * Indicates that a registration is being performed. // */ // REGISTERING(3); // // private int value; // // State(int value) { // this.value = value; // } // // public int getValue() { // return value; // } // // @Nullable // public static State fromValue(final int fromValue) { // final State[] values = values(); // for (final State state : values) { // final int stateValue = state.getValue(); // if (stateValue == fromValue) { // return state; // } // } // // return null; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // static final String ACTION_CHECK_REGISTERING_TIMEOUT = BuildConfig.APPLICATION_ID + "intent.CHECK_REGISTERING_TIMEOUT"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfpush.model.State; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFUtils; import java.util.Locale; import static org.onepf.opfpush.OPFConstants.ACTION_CHECK_REGISTERING_TIMEOUT; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush; /** * @author Kirill Rozov * @author Roman Savin * @since 01.10.14. */ public final class RetryBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { OPFLog.logMethod(context, OPFUtils.toString(intent)); final OPFPushHelper helper = OPFPush.getHelper(); if (helper.isInitDone()) { OPFLog.d("Initialisation is done"); final String action = intent.getAction();
final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME);
onepf/OPFPush
opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java
// Path: opfpush/src/main/java/org/onepf/opfpush/model/State.java // public enum State { // // /** // * Indicates that an unregistration has been completed. // */ // UNREGISTERED(0), // // /** // * Indicates that a registration has been completed. // */ // REGISTERED(2), // // /** // * Indicates that a registration is being performed. // */ // REGISTERING(3); // // private int value; // // State(int value) { // this.value = value; // } // // public int getValue() { // return value; // } // // @Nullable // public static State fromValue(final int fromValue) { // final State[] values = values(); // for (final State state : values) { // final int stateValue = state.getValue(); // if (stateValue == fromValue) { // return state; // } // } // // return null; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // static final String ACTION_CHECK_REGISTERING_TIMEOUT = BuildConfig.APPLICATION_ID + "intent.CHECK_REGISTERING_TIMEOUT"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME";
import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfpush.model.State; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFUtils; import java.util.Locale; import static org.onepf.opfpush.OPFConstants.ACTION_CHECK_REGISTERING_TIMEOUT; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush; /** * @author Kirill Rozov * @author Roman Savin * @since 01.10.14. */ public final class RetryBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { OPFLog.logMethod(context, OPFUtils.toString(intent)); final OPFPushHelper helper = OPFPush.getHelper(); if (helper.isInitDone()) { OPFLog.d("Initialisation is done"); final String action = intent.getAction(); final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); switch (action) {
// Path: opfpush/src/main/java/org/onepf/opfpush/model/State.java // public enum State { // // /** // * Indicates that an unregistration has been completed. // */ // UNREGISTERED(0), // // /** // * Indicates that a registration has been completed. // */ // REGISTERED(2), // // /** // * Indicates that a registration is being performed. // */ // REGISTERING(3); // // private int value; // // State(int value) { // this.value = value; // } // // public int getValue() { // return value; // } // // @Nullable // public static State fromValue(final int fromValue) { // final State[] values = values(); // for (final State state : values) { // final int stateValue = state.getValue(); // if (stateValue == fromValue) { // return state; // } // } // // return null; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // static final String ACTION_CHECK_REGISTERING_TIMEOUT = BuildConfig.APPLICATION_ID + "intent.CHECK_REGISTERING_TIMEOUT"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfpush.model.State; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFUtils; import java.util.Locale; import static org.onepf.opfpush.OPFConstants.ACTION_CHECK_REGISTERING_TIMEOUT; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush; /** * @author Kirill Rozov * @author Roman Savin * @since 01.10.14. */ public final class RetryBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { OPFLog.logMethod(context, OPFUtils.toString(intent)); final OPFPushHelper helper = OPFPush.getHelper(); if (helper.isInitDone()) { OPFLog.d("Initialisation is done"); final String action = intent.getAction(); final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); switch (action) {
case ACTION_RETRY_REGISTER:
onepf/OPFPush
opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java
// Path: opfpush/src/main/java/org/onepf/opfpush/model/State.java // public enum State { // // /** // * Indicates that an unregistration has been completed. // */ // UNREGISTERED(0), // // /** // * Indicates that a registration has been completed. // */ // REGISTERED(2), // // /** // * Indicates that a registration is being performed. // */ // REGISTERING(3); // // private int value; // // State(int value) { // this.value = value; // } // // public int getValue() { // return value; // } // // @Nullable // public static State fromValue(final int fromValue) { // final State[] values = values(); // for (final State state : values) { // final int stateValue = state.getValue(); // if (stateValue == fromValue) { // return state; // } // } // // return null; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // static final String ACTION_CHECK_REGISTERING_TIMEOUT = BuildConfig.APPLICATION_ID + "intent.CHECK_REGISTERING_TIMEOUT"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME";
import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfpush.model.State; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFUtils; import java.util.Locale; import static org.onepf.opfpush.OPFConstants.ACTION_CHECK_REGISTERING_TIMEOUT; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush; /** * @author Kirill Rozov * @author Roman Savin * @since 01.10.14. */ public final class RetryBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { OPFLog.logMethod(context, OPFUtils.toString(intent)); final OPFPushHelper helper = OPFPush.getHelper(); if (helper.isInitDone()) { OPFLog.d("Initialisation is done"); final String action = intent.getAction(); final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); switch (action) { case ACTION_RETRY_REGISTER: helper.register(providerName); break;
// Path: opfpush/src/main/java/org/onepf/opfpush/model/State.java // public enum State { // // /** // * Indicates that an unregistration has been completed. // */ // UNREGISTERED(0), // // /** // * Indicates that a registration has been completed. // */ // REGISTERED(2), // // /** // * Indicates that a registration is being performed. // */ // REGISTERING(3); // // private int value; // // State(int value) { // this.value = value; // } // // public int getValue() { // return value; // } // // @Nullable // public static State fromValue(final int fromValue) { // final State[] values = values(); // for (final State state : values) { // final int stateValue = state.getValue(); // if (stateValue == fromValue) { // return state; // } // } // // return null; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // static final String ACTION_CHECK_REGISTERING_TIMEOUT = BuildConfig.APPLICATION_ID + "intent.CHECK_REGISTERING_TIMEOUT"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfpush.model.State; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFUtils; import java.util.Locale; import static org.onepf.opfpush.OPFConstants.ACTION_CHECK_REGISTERING_TIMEOUT; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush; /** * @author Kirill Rozov * @author Roman Savin * @since 01.10.14. */ public final class RetryBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { OPFLog.logMethod(context, OPFUtils.toString(intent)); final OPFPushHelper helper = OPFPush.getHelper(); if (helper.isInitDone()) { OPFLog.d("Initialisation is done"); final String action = intent.getAction(); final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); switch (action) { case ACTION_RETRY_REGISTER: helper.register(providerName); break;
case ACTION_RETRY_UNREGISTER:
onepf/OPFPush
opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java
// Path: opfpush/src/main/java/org/onepf/opfpush/model/State.java // public enum State { // // /** // * Indicates that an unregistration has been completed. // */ // UNREGISTERED(0), // // /** // * Indicates that a registration has been completed. // */ // REGISTERED(2), // // /** // * Indicates that a registration is being performed. // */ // REGISTERING(3); // // private int value; // // State(int value) { // this.value = value; // } // // public int getValue() { // return value; // } // // @Nullable // public static State fromValue(final int fromValue) { // final State[] values = values(); // for (final State state : values) { // final int stateValue = state.getValue(); // if (stateValue == fromValue) { // return state; // } // } // // return null; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // static final String ACTION_CHECK_REGISTERING_TIMEOUT = BuildConfig.APPLICATION_ID + "intent.CHECK_REGISTERING_TIMEOUT"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME";
import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfpush.model.State; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFUtils; import java.util.Locale; import static org.onepf.opfpush.OPFConstants.ACTION_CHECK_REGISTERING_TIMEOUT; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush; /** * @author Kirill Rozov * @author Roman Savin * @since 01.10.14. */ public final class RetryBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { OPFLog.logMethod(context, OPFUtils.toString(intent)); final OPFPushHelper helper = OPFPush.getHelper(); if (helper.isInitDone()) { OPFLog.d("Initialisation is done"); final String action = intent.getAction(); final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); switch (action) { case ACTION_RETRY_REGISTER: helper.register(providerName); break; case ACTION_RETRY_UNREGISTER: helper.unregister(providerName); break;
// Path: opfpush/src/main/java/org/onepf/opfpush/model/State.java // public enum State { // // /** // * Indicates that an unregistration has been completed. // */ // UNREGISTERED(0), // // /** // * Indicates that a registration has been completed. // */ // REGISTERED(2), // // /** // * Indicates that a registration is being performed. // */ // REGISTERING(3); // // private int value; // // State(int value) { // this.value = value; // } // // public int getValue() { // return value; // } // // @Nullable // public static State fromValue(final int fromValue) { // final State[] values = values(); // for (final State state : values) { // final int stateValue = state.getValue(); // if (stateValue == fromValue) { // return state; // } // } // // return null; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // static final String ACTION_CHECK_REGISTERING_TIMEOUT = BuildConfig.APPLICATION_ID + "intent.CHECK_REGISTERING_TIMEOUT"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfpush.model.State; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFUtils; import java.util.Locale; import static org.onepf.opfpush.OPFConstants.ACTION_CHECK_REGISTERING_TIMEOUT; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush; /** * @author Kirill Rozov * @author Roman Savin * @since 01.10.14. */ public final class RetryBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(@NonNull final Context context, @NonNull final Intent intent) { OPFLog.logMethod(context, OPFUtils.toString(intent)); final OPFPushHelper helper = OPFPush.getHelper(); if (helper.isInitDone()) { OPFLog.d("Initialisation is done"); final String action = intent.getAction(); final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); switch (action) { case ACTION_RETRY_REGISTER: helper.register(providerName); break; case ACTION_RETRY_UNREGISTER: helper.unregister(providerName); break;
case ACTION_CHECK_REGISTERING_TIMEOUT:
onepf/OPFPush
opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java
// Path: opfpush/src/main/java/org/onepf/opfpush/model/State.java // public enum State { // // /** // * Indicates that an unregistration has been completed. // */ // UNREGISTERED(0), // // /** // * Indicates that a registration has been completed. // */ // REGISTERED(2), // // /** // * Indicates that a registration is being performed. // */ // REGISTERING(3); // // private int value; // // State(int value) { // this.value = value; // } // // public int getValue() { // return value; // } // // @Nullable // public static State fromValue(final int fromValue) { // final State[] values = values(); // for (final State state : values) { // final int stateValue = state.getValue(); // if (stateValue == fromValue) { // return state; // } // } // // return null; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // static final String ACTION_CHECK_REGISTERING_TIMEOUT = BuildConfig.APPLICATION_ID + "intent.CHECK_REGISTERING_TIMEOUT"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME";
import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfpush.model.State; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFUtils; import java.util.Locale; import static org.onepf.opfpush.OPFConstants.ACTION_CHECK_REGISTERING_TIMEOUT; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER;
final OPFPushHelper helper = OPFPush.getHelper(); if (helper.isInitDone()) { OPFLog.d("Initialisation is done"); final String action = intent.getAction(); final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); switch (action) { case ACTION_RETRY_REGISTER: helper.register(providerName); break; case ACTION_RETRY_UNREGISTER: helper.unregister(providerName); break; case ACTION_CHECK_REGISTERING_TIMEOUT: checkRegistering(context, helper, providerName); break; default: throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); } } else { OPFLog.w("OPFPush must be initialized"); } } private void checkRegistering(@NonNull final Context context, @NonNull final OPFPushHelper helper, @NonNull final String providerName) { OPFLog.logMethod(context, helper, providerName); if (helper.isRegistering()) {
// Path: opfpush/src/main/java/org/onepf/opfpush/model/State.java // public enum State { // // /** // * Indicates that an unregistration has been completed. // */ // UNREGISTERED(0), // // /** // * Indicates that a registration has been completed. // */ // REGISTERED(2), // // /** // * Indicates that a registration is being performed. // */ // REGISTERING(3); // // private int value; // // State(int value) { // this.value = value; // } // // public int getValue() { // return value; // } // // @Nullable // public static State fromValue(final int fromValue) { // final State[] values = values(); // for (final State state : values) { // final int stateValue = state.getValue(); // if (stateValue == fromValue) { // return state; // } // } // // return null; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // static final String ACTION_CHECK_REGISTERING_TIMEOUT = BuildConfig.APPLICATION_ID + "intent.CHECK_REGISTERING_TIMEOUT"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER"; // // Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java // public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME"; // Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import org.onepf.opfpush.model.State; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFUtils; import java.util.Locale; import static org.onepf.opfpush.OPFConstants.ACTION_CHECK_REGISTERING_TIMEOUT; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER; import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER; final OPFPushHelper helper = OPFPush.getHelper(); if (helper.isInitDone()) { OPFLog.d("Initialisation is done"); final String action = intent.getAction(); final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME); switch (action) { case ACTION_RETRY_REGISTER: helper.register(providerName); break; case ACTION_RETRY_UNREGISTER: helper.unregister(providerName); break; case ACTION_CHECK_REGISTERING_TIMEOUT: checkRegistering(context, helper, providerName); break; default: throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action)); } } else { OPFLog.w("OPFPush must be initialized"); } } private void checkRegistering(@NonNull final Context context, @NonNull final OPFPushHelper helper, @NonNull final String providerName) { OPFLog.logMethod(context, helper, providerName); if (helper.isRegistering()) {
Settings.getInstance(context).saveState(State.UNREGISTERED);
onepf/OPFPush
samples/pushchat/src/main/java/org/onepf/pushchat/ui/adapter/ContactsCursorAdapter.java
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static final String NAME = "name"; // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static final String UUID = "uuid";
import android.content.Context; import android.database.Cursor; import android.support.annotation.NonNull; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CursorAdapter; import android.widget.TextView; import org.onepf.pushchat.R; import static org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry.NAME; import static org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry.UUID;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.pushchat.ui.adapter; /** * @author Roman Savin * @since 07.05.2015 */ public class ContactsCursorAdapter extends CursorAdapter { public ContactsCursorAdapter(@NonNull final Context context) { super(context, null, FLAG_REGISTER_CONTENT_OBSERVER); } @Override public View newView(final Context context, final Cursor cursor, final ViewGroup parent) { return LayoutInflater.from(context).inflate(R.layout.item_contact, parent, false); } @Override public void bindView(final View view, final Context context, final Cursor cursor) {
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static final String NAME = "name"; // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static final String UUID = "uuid"; // Path: samples/pushchat/src/main/java/org/onepf/pushchat/ui/adapter/ContactsCursorAdapter.java import android.content.Context; import android.database.Cursor; import android.support.annotation.NonNull; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CursorAdapter; import android.widget.TextView; import org.onepf.pushchat.R; import static org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry.NAME; import static org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry.UUID; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.pushchat.ui.adapter; /** * @author Roman Savin * @since 07.05.2015 */ public class ContactsCursorAdapter extends CursorAdapter { public ContactsCursorAdapter(@NonNull final Context context) { super(context, null, FLAG_REGISTER_CONTENT_OBSERVER); } @Override public View newView(final Context context, final Cursor cursor, final ViewGroup parent) { return LayoutInflater.from(context).inflate(R.layout.item_contact, parent, false); } @Override public void bindView(final View view, final Context context, final Cursor cursor) {
final String name = cursor.getString(cursor.getColumnIndexOrThrow(NAME));
onepf/OPFPush
samples/pushchat/src/main/java/org/onepf/pushchat/ui/adapter/ContactsCursorAdapter.java
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static final String NAME = "name"; // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static final String UUID = "uuid";
import android.content.Context; import android.database.Cursor; import android.support.annotation.NonNull; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CursorAdapter; import android.widget.TextView; import org.onepf.pushchat.R; import static org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry.NAME; import static org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry.UUID;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.pushchat.ui.adapter; /** * @author Roman Savin * @since 07.05.2015 */ public class ContactsCursorAdapter extends CursorAdapter { public ContactsCursorAdapter(@NonNull final Context context) { super(context, null, FLAG_REGISTER_CONTENT_OBSERVER); } @Override public View newView(final Context context, final Cursor cursor, final ViewGroup parent) { return LayoutInflater.from(context).inflate(R.layout.item_contact, parent, false); } @Override public void bindView(final View view, final Context context, final Cursor cursor) { final String name = cursor.getString(cursor.getColumnIndexOrThrow(NAME));
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static final String NAME = "name"; // // Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java // public static final String UUID = "uuid"; // Path: samples/pushchat/src/main/java/org/onepf/pushchat/ui/adapter/ContactsCursorAdapter.java import android.content.Context; import android.database.Cursor; import android.support.annotation.NonNull; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CursorAdapter; import android.widget.TextView; import org.onepf.pushchat.R; import static org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry.NAME; import static org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry.UUID; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.pushchat.ui.adapter; /** * @author Roman Savin * @since 07.05.2015 */ public class ContactsCursorAdapter extends CursorAdapter { public ContactsCursorAdapter(@NonNull final Context context) { super(context, null, FLAG_REGISTER_CONTENT_OBSERVER); } @Override public View newView(final Context context, final Cursor cursor, final ViewGroup parent) { return LayoutInflater.from(context).inflate(R.layout.item_contact, parent, false); } @Override public void bindView(final View view, final Context context, final Cursor cursor) { final String name = cursor.getString(cursor.getColumnIndexOrThrow(NAME));
final String uuid = cursor.getString(cursor.getColumnIndexOrThrow(UUID));
onepf/OPFPush
opfpush/src/main/java/org/onepf/opfpush/Settings.java
// Path: opfpush/src/main/java/org/onepf/opfpush/model/State.java // public enum State { // // /** // * Indicates that an unregistration has been completed. // */ // UNREGISTERED(0), // // /** // * Indicates that a registration has been completed. // */ // REGISTERED(2), // // /** // * Indicates that a registration is being performed. // */ // REGISTERING(3); // // private int value; // // State(int value) { // this.value = value; // } // // public int getValue() { // return value; // } // // @Nullable // public static State fromValue(final int fromValue) { // final State[] values = values(); // for (final State state : values) { // final int stateValue = state.getValue(); // if (stateValue == fromValue) { // return state; // } // } // // return null; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/pushprovider/PushProvider.java // public interface PushProvider { // /** // * Initiates the registration of the provider. Must be async. // * <p/> // * Intended for the internal use, should never be called directly. // * To start the registration call {@link org.onepf.opfpush.OPFPushHelper#register()}. // */ // void register(); // // /** // * Initiates the unregistering of the provider. Must be async. // * <p/> // * Intended for internal use, should never be called directly. // * To start registration call {@link org.onepf.opfpush.OPFPushHelper#unregister()}. // */ // void unregister(); // // /** // * Checks whether the provider is available. // * // * @return The instance of {@link org.onepf.opfpush.model.AvailabilityResult} // * that contains result of availability check. // */ // @NonNull // AvailabilityResult getAvailabilityResult(); // // /** // * Checks whether the application was successfully registered on the service. // * // * @return {@code true} if the application was successfully registered on the service, otherwise false. // */ // boolean isRegistered(); // // /** // * Returns the registration ID or null if provider isn't registered. // * // * @return The registration ID or null if provider isn't registered. // */ // @Nullable // String getRegistrationId(); // // /** // * Returns the name of the provider. Must be unique for all providers. // * // * @return The name of the provider. // */ // @NonNull // String getName(); // // /** // * Returns the package of the application that contains API of the provider. // * Usually, this is a store application. // * // * @return The package of the application that contains API of the provider. // */ // @Nullable // String getHostAppPackage(); // // /** // * Returns the {@link NotificationMaker} object associated with provider. // * // * @return The {@link NotificationMaker} instance. // */ // @NonNull // NotificationMaker getNotificationMaker(); // // /** // * Verify that application manifest contains all needed permissions. // * // * @param checkManifestHandler If not null an exception isn't thrown. // * @throws java.lang.IllegalStateException If not all required permissions and components have been // * described in the AndroidManifest.xml file. // */ // void checkManifest(@Nullable CheckManifestHandler checkManifestHandler); // // /** // * Callback method, that called when the application state change, like update to new version, // * or system state changed, like update firmware to a newer version. // * <p/> // * If this method is called, your registration becomes invalid // * and you have to reset all saved registration data. // */ // void onRegistrationInvalid(); // // /** // * Callback method for notify that the provider became unavailable. // * In this method you have to reset all saved registration data. // */ // void onUnavailable(); // }
import android.content.Context; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.model.State; import org.onepf.opfpush.pushprovider.PushProvider; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFPreferences; import java.util.Locale; import static org.onepf.opfpush.model.State.UNREGISTERED;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush; /** * @author Kirill Rozov * @author Roman Savin * @since 01.10.14. */ @SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel") final class Settings { private static final String KEY_LAST_PROVIDER_NAME = "last_provider_name"; private static final String KEY_STATE = "state"; private static final String KEY_LAST_ANDROID_ID = "android_id"; private static final String KEY_UNREGISTERING_PROVIDER_PREFIX = "unregistering_provider_"; private static final String KEY_REGISTERING_PROVIDER_PREFIX = "registering_provider_"; private static final String KEY_PENDING_REGISTRATION_PROVIDER = "pending_registration_provider"; private static final String KEY_PENDING_UNREGISTRATION_PROVIDER = "pending_unregistration_provider"; private static final String OPF_CORE_POSTFIX = "opfpush"; private static volatile Settings instance; @NonNull private final OPFPreferences preferences; private Settings(@NonNull final Context context) { preferences = new OPFPreferences(context, OPF_CORE_POSTFIX); } @SuppressWarnings("PMD.NonThreadSafeSingleton") public static Settings getInstance(@NonNull final Context context) { OPFChecks.checkThread(true); if (instance == null) { instance = new Settings(context); } return instance; } @NonNull
// Path: opfpush/src/main/java/org/onepf/opfpush/model/State.java // public enum State { // // /** // * Indicates that an unregistration has been completed. // */ // UNREGISTERED(0), // // /** // * Indicates that a registration has been completed. // */ // REGISTERED(2), // // /** // * Indicates that a registration is being performed. // */ // REGISTERING(3); // // private int value; // // State(int value) { // this.value = value; // } // // public int getValue() { // return value; // } // // @Nullable // public static State fromValue(final int fromValue) { // final State[] values = values(); // for (final State state : values) { // final int stateValue = state.getValue(); // if (stateValue == fromValue) { // return state; // } // } // // return null; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/pushprovider/PushProvider.java // public interface PushProvider { // /** // * Initiates the registration of the provider. Must be async. // * <p/> // * Intended for the internal use, should never be called directly. // * To start the registration call {@link org.onepf.opfpush.OPFPushHelper#register()}. // */ // void register(); // // /** // * Initiates the unregistering of the provider. Must be async. // * <p/> // * Intended for internal use, should never be called directly. // * To start registration call {@link org.onepf.opfpush.OPFPushHelper#unregister()}. // */ // void unregister(); // // /** // * Checks whether the provider is available. // * // * @return The instance of {@link org.onepf.opfpush.model.AvailabilityResult} // * that contains result of availability check. // */ // @NonNull // AvailabilityResult getAvailabilityResult(); // // /** // * Checks whether the application was successfully registered on the service. // * // * @return {@code true} if the application was successfully registered on the service, otherwise false. // */ // boolean isRegistered(); // // /** // * Returns the registration ID or null if provider isn't registered. // * // * @return The registration ID or null if provider isn't registered. // */ // @Nullable // String getRegistrationId(); // // /** // * Returns the name of the provider. Must be unique for all providers. // * // * @return The name of the provider. // */ // @NonNull // String getName(); // // /** // * Returns the package of the application that contains API of the provider. // * Usually, this is a store application. // * // * @return The package of the application that contains API of the provider. // */ // @Nullable // String getHostAppPackage(); // // /** // * Returns the {@link NotificationMaker} object associated with provider. // * // * @return The {@link NotificationMaker} instance. // */ // @NonNull // NotificationMaker getNotificationMaker(); // // /** // * Verify that application manifest contains all needed permissions. // * // * @param checkManifestHandler If not null an exception isn't thrown. // * @throws java.lang.IllegalStateException If not all required permissions and components have been // * described in the AndroidManifest.xml file. // */ // void checkManifest(@Nullable CheckManifestHandler checkManifestHandler); // // /** // * Callback method, that called when the application state change, like update to new version, // * or system state changed, like update firmware to a newer version. // * <p/> // * If this method is called, your registration becomes invalid // * and you have to reset all saved registration data. // */ // void onRegistrationInvalid(); // // /** // * Callback method for notify that the provider became unavailable. // * In this method you have to reset all saved registration data. // */ // void onUnavailable(); // } // Path: opfpush/src/main/java/org/onepf/opfpush/Settings.java import android.content.Context; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.model.State; import org.onepf.opfpush.pushprovider.PushProvider; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFPreferences; import java.util.Locale; import static org.onepf.opfpush.model.State.UNREGISTERED; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush; /** * @author Kirill Rozov * @author Roman Savin * @since 01.10.14. */ @SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel") final class Settings { private static final String KEY_LAST_PROVIDER_NAME = "last_provider_name"; private static final String KEY_STATE = "state"; private static final String KEY_LAST_ANDROID_ID = "android_id"; private static final String KEY_UNREGISTERING_PROVIDER_PREFIX = "unregistering_provider_"; private static final String KEY_REGISTERING_PROVIDER_PREFIX = "registering_provider_"; private static final String KEY_PENDING_REGISTRATION_PROVIDER = "pending_registration_provider"; private static final String KEY_PENDING_UNREGISTRATION_PROVIDER = "pending_unregistration_provider"; private static final String OPF_CORE_POSTFIX = "opfpush"; private static volatile Settings instance; @NonNull private final OPFPreferences preferences; private Settings(@NonNull final Context context) { preferences = new OPFPreferences(context, OPF_CORE_POSTFIX); } @SuppressWarnings("PMD.NonThreadSafeSingleton") public static Settings getInstance(@NonNull final Context context) { OPFChecks.checkThread(true); if (instance == null) { instance = new Settings(context); } return instance; } @NonNull
public synchronized State getState() {
onepf/OPFPush
opfpush/src/main/java/org/onepf/opfpush/Settings.java
// Path: opfpush/src/main/java/org/onepf/opfpush/model/State.java // public enum State { // // /** // * Indicates that an unregistration has been completed. // */ // UNREGISTERED(0), // // /** // * Indicates that a registration has been completed. // */ // REGISTERED(2), // // /** // * Indicates that a registration is being performed. // */ // REGISTERING(3); // // private int value; // // State(int value) { // this.value = value; // } // // public int getValue() { // return value; // } // // @Nullable // public static State fromValue(final int fromValue) { // final State[] values = values(); // for (final State state : values) { // final int stateValue = state.getValue(); // if (stateValue == fromValue) { // return state; // } // } // // return null; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/pushprovider/PushProvider.java // public interface PushProvider { // /** // * Initiates the registration of the provider. Must be async. // * <p/> // * Intended for the internal use, should never be called directly. // * To start the registration call {@link org.onepf.opfpush.OPFPushHelper#register()}. // */ // void register(); // // /** // * Initiates the unregistering of the provider. Must be async. // * <p/> // * Intended for internal use, should never be called directly. // * To start registration call {@link org.onepf.opfpush.OPFPushHelper#unregister()}. // */ // void unregister(); // // /** // * Checks whether the provider is available. // * // * @return The instance of {@link org.onepf.opfpush.model.AvailabilityResult} // * that contains result of availability check. // */ // @NonNull // AvailabilityResult getAvailabilityResult(); // // /** // * Checks whether the application was successfully registered on the service. // * // * @return {@code true} if the application was successfully registered on the service, otherwise false. // */ // boolean isRegistered(); // // /** // * Returns the registration ID or null if provider isn't registered. // * // * @return The registration ID or null if provider isn't registered. // */ // @Nullable // String getRegistrationId(); // // /** // * Returns the name of the provider. Must be unique for all providers. // * // * @return The name of the provider. // */ // @NonNull // String getName(); // // /** // * Returns the package of the application that contains API of the provider. // * Usually, this is a store application. // * // * @return The package of the application that contains API of the provider. // */ // @Nullable // String getHostAppPackage(); // // /** // * Returns the {@link NotificationMaker} object associated with provider. // * // * @return The {@link NotificationMaker} instance. // */ // @NonNull // NotificationMaker getNotificationMaker(); // // /** // * Verify that application manifest contains all needed permissions. // * // * @param checkManifestHandler If not null an exception isn't thrown. // * @throws java.lang.IllegalStateException If not all required permissions and components have been // * described in the AndroidManifest.xml file. // */ // void checkManifest(@Nullable CheckManifestHandler checkManifestHandler); // // /** // * Callback method, that called when the application state change, like update to new version, // * or system state changed, like update firmware to a newer version. // * <p/> // * If this method is called, your registration becomes invalid // * and you have to reset all saved registration data. // */ // void onRegistrationInvalid(); // // /** // * Callback method for notify that the provider became unavailable. // * In this method you have to reset all saved registration data. // */ // void onUnavailable(); // }
import android.content.Context; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.model.State; import org.onepf.opfpush.pushprovider.PushProvider; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFPreferences; import java.util.Locale; import static org.onepf.opfpush.model.State.UNREGISTERED;
@NonNull public synchronized State getState() { OPFLog.logMethod(); final int stateValue = preferences.getInt(KEY_STATE, UNREGISTERED.getValue()); State state = State.fromValue(stateValue); OPFLog.d("State : " + state); if (state == null) { state = UNREGISTERED; saveState(state); } return state; } public synchronized void saveState(@NonNull final State state) { OPFLog.logMethod(state); preferences.put(KEY_STATE, state.getValue()); } public synchronized void clear() { OPFLog.logMethod(); preferences.clear(); } @Nullable public synchronized String getLastProviderName() { return preferences.getString(KEY_LAST_PROVIDER_NAME); }
// Path: opfpush/src/main/java/org/onepf/opfpush/model/State.java // public enum State { // // /** // * Indicates that an unregistration has been completed. // */ // UNREGISTERED(0), // // /** // * Indicates that a registration has been completed. // */ // REGISTERED(2), // // /** // * Indicates that a registration is being performed. // */ // REGISTERING(3); // // private int value; // // State(int value) { // this.value = value; // } // // public int getValue() { // return value; // } // // @Nullable // public static State fromValue(final int fromValue) { // final State[] values = values(); // for (final State state : values) { // final int stateValue = state.getValue(); // if (stateValue == fromValue) { // return state; // } // } // // return null; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/pushprovider/PushProvider.java // public interface PushProvider { // /** // * Initiates the registration of the provider. Must be async. // * <p/> // * Intended for the internal use, should never be called directly. // * To start the registration call {@link org.onepf.opfpush.OPFPushHelper#register()}. // */ // void register(); // // /** // * Initiates the unregistering of the provider. Must be async. // * <p/> // * Intended for internal use, should never be called directly. // * To start registration call {@link org.onepf.opfpush.OPFPushHelper#unregister()}. // */ // void unregister(); // // /** // * Checks whether the provider is available. // * // * @return The instance of {@link org.onepf.opfpush.model.AvailabilityResult} // * that contains result of availability check. // */ // @NonNull // AvailabilityResult getAvailabilityResult(); // // /** // * Checks whether the application was successfully registered on the service. // * // * @return {@code true} if the application was successfully registered on the service, otherwise false. // */ // boolean isRegistered(); // // /** // * Returns the registration ID or null if provider isn't registered. // * // * @return The registration ID or null if provider isn't registered. // */ // @Nullable // String getRegistrationId(); // // /** // * Returns the name of the provider. Must be unique for all providers. // * // * @return The name of the provider. // */ // @NonNull // String getName(); // // /** // * Returns the package of the application that contains API of the provider. // * Usually, this is a store application. // * // * @return The package of the application that contains API of the provider. // */ // @Nullable // String getHostAppPackage(); // // /** // * Returns the {@link NotificationMaker} object associated with provider. // * // * @return The {@link NotificationMaker} instance. // */ // @NonNull // NotificationMaker getNotificationMaker(); // // /** // * Verify that application manifest contains all needed permissions. // * // * @param checkManifestHandler If not null an exception isn't thrown. // * @throws java.lang.IllegalStateException If not all required permissions and components have been // * described in the AndroidManifest.xml file. // */ // void checkManifest(@Nullable CheckManifestHandler checkManifestHandler); // // /** // * Callback method, that called when the application state change, like update to new version, // * or system state changed, like update firmware to a newer version. // * <p/> // * If this method is called, your registration becomes invalid // * and you have to reset all saved registration data. // */ // void onRegistrationInvalid(); // // /** // * Callback method for notify that the provider became unavailable. // * In this method you have to reset all saved registration data. // */ // void onUnavailable(); // } // Path: opfpush/src/main/java/org/onepf/opfpush/Settings.java import android.content.Context; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.model.State; import org.onepf.opfpush.pushprovider.PushProvider; import org.onepf.opfutils.OPFChecks; import org.onepf.opfutils.OPFLog; import org.onepf.opfutils.OPFPreferences; import java.util.Locale; import static org.onepf.opfpush.model.State.UNREGISTERED; @NonNull public synchronized State getState() { OPFLog.logMethod(); final int stateValue = preferences.getInt(KEY_STATE, UNREGISTERED.getValue()); State state = State.fromValue(stateValue); OPFLog.d("State : " + state); if (state == null) { state = UNREGISTERED; saveState(state); } return state; } public synchronized void saveState(@NonNull final State state) { OPFLog.logMethod(state); preferences.put(KEY_STATE, state.getValue()); } public synchronized void clear() { OPFLog.logMethod(); preferences.clear(); } @Nullable public synchronized String getLastProviderName() { return preferences.getString(KEY_LAST_PROVIDER_NAME); }
public synchronized void saveLastProvider(@Nullable final PushProvider provider) {
onepf/OPFPush
opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaNotificationsProvider.java
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // } // // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaPushConstants.java // static final String NOKIA_MANUFACTURER = "Nokia";
import android.content.Context; import android.os.Build; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker; import org.onepf.opfutils.OPFLog; import static org.onepf.opfpush.nokia.NokiaPushConstants.NOKIA_MANUFACTURER;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.nokia; /** * Nokia Notification push provider delegate. * * @author Kirill Rozov * @author Roman Savin * @see <a href="http://developer.nokia.com/resources/library/nokia-x/nokia-notifications.html">Nokia Notification</a> * @since 06.09.14 */ @SuppressWarnings("PMD.AvoidDuplicateLiterals") public class NokiaNotificationsProvider implements NokiaPushProvider { private final NokiaPushProvider provider; public NokiaNotificationsProvider(@NonNull final Context context, @NonNull final String... sendersIds) {
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // } // // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaPushConstants.java // static final String NOKIA_MANUFACTURER = "Nokia"; // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaNotificationsProvider.java import android.content.Context; import android.os.Build; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker; import org.onepf.opfutils.OPFLog; import static org.onepf.opfpush.nokia.NokiaPushConstants.NOKIA_MANUFACTURER; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.nokia; /** * Nokia Notification push provider delegate. * * @author Kirill Rozov * @author Roman Savin * @see <a href="http://developer.nokia.com/resources/library/nokia-x/nokia-notifications.html">Nokia Notification</a> * @since 06.09.14 */ @SuppressWarnings("PMD.AvoidDuplicateLiterals") public class NokiaNotificationsProvider implements NokiaPushProvider { private final NokiaPushProvider provider; public NokiaNotificationsProvider(@NonNull final Context context, @NonNull final String... sendersIds) {
if (Build.MANUFACTURER.equals(NOKIA_MANUFACTURER)) {
onepf/OPFPush
opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaNotificationsProvider.java
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // } // // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaPushConstants.java // static final String NOKIA_MANUFACTURER = "Nokia";
import android.content.Context; import android.os.Build; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker; import org.onepf.opfutils.OPFLog; import static org.onepf.opfpush.nokia.NokiaPushConstants.NOKIA_MANUFACTURER;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.nokia; /** * Nokia Notification push provider delegate. * * @author Kirill Rozov * @author Roman Savin * @see <a href="http://developer.nokia.com/resources/library/nokia-x/nokia-notifications.html">Nokia Notification</a> * @since 06.09.14 */ @SuppressWarnings("PMD.AvoidDuplicateLiterals") public class NokiaNotificationsProvider implements NokiaPushProvider { private final NokiaPushProvider provider; public NokiaNotificationsProvider(@NonNull final Context context, @NonNull final String... sendersIds) { if (Build.MANUFACTURER.equals(NOKIA_MANUFACTURER)) { OPFLog.d("It's a Nokia device."); provider = new NokiaNotificationsProviderImpl(context, sendersIds); } else { OPFLog.d("It's no a Nokia device."); provider = new NokiaNotificationsProviderStub(); } } public NokiaNotificationsProvider(@NonNull final Context context,
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // } // // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaPushConstants.java // static final String NOKIA_MANUFACTURER = "Nokia"; // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaNotificationsProvider.java import android.content.Context; import android.os.Build; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker; import org.onepf.opfutils.OPFLog; import static org.onepf.opfpush.nokia.NokiaPushConstants.NOKIA_MANUFACTURER; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.nokia; /** * Nokia Notification push provider delegate. * * @author Kirill Rozov * @author Roman Savin * @see <a href="http://developer.nokia.com/resources/library/nokia-x/nokia-notifications.html">Nokia Notification</a> * @since 06.09.14 */ @SuppressWarnings("PMD.AvoidDuplicateLiterals") public class NokiaNotificationsProvider implements NokiaPushProvider { private final NokiaPushProvider provider; public NokiaNotificationsProvider(@NonNull final Context context, @NonNull final String... sendersIds) { if (Build.MANUFACTURER.equals(NOKIA_MANUFACTURER)) { OPFLog.d("It's a Nokia device."); provider = new NokiaNotificationsProviderImpl(context, sendersIds); } else { OPFLog.d("It's no a Nokia device."); provider = new NokiaNotificationsProviderStub(); } } public NokiaNotificationsProvider(@NonNull final Context context,
@NonNull final NotificationMaker notificationMaker,
onepf/OPFPush
opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaNotificationsProvider.java
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // } // // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaPushConstants.java // static final String NOKIA_MANUFACTURER = "Nokia";
import android.content.Context; import android.os.Build; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker; import org.onepf.opfutils.OPFLog; import static org.onepf.opfpush.nokia.NokiaPushConstants.NOKIA_MANUFACTURER;
} else { OPFLog.d("It's no a Nokia device."); provider = new NokiaNotificationsProviderStub(); } } public NokiaNotificationsProvider(@NonNull final Context context, @NonNull final NotificationMaker notificationMaker, @NonNull final String... sendersIds) { if (Build.MANUFACTURER.equals(NOKIA_MANUFACTURER)) { OPFLog.d("It's a Nokia device."); provider = new NokiaNotificationsProviderImpl(context, notificationMaker, sendersIds); } else { OPFLog.d("It's no a Nokia device."); provider = new NokiaNotificationsProviderStub(); } } @Override public void register() { provider.register(); } @Override public void unregister() { provider.unregister(); } @NonNull @Override
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // } // // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaPushConstants.java // static final String NOKIA_MANUFACTURER = "Nokia"; // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaNotificationsProvider.java import android.content.Context; import android.os.Build; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker; import org.onepf.opfutils.OPFLog; import static org.onepf.opfpush.nokia.NokiaPushConstants.NOKIA_MANUFACTURER; } else { OPFLog.d("It's no a Nokia device."); provider = new NokiaNotificationsProviderStub(); } } public NokiaNotificationsProvider(@NonNull final Context context, @NonNull final NotificationMaker notificationMaker, @NonNull final String... sendersIds) { if (Build.MANUFACTURER.equals(NOKIA_MANUFACTURER)) { OPFLog.d("It's a Nokia device."); provider = new NokiaNotificationsProviderImpl(context, notificationMaker, sendersIds); } else { OPFLog.d("It's no a Nokia device."); provider = new NokiaNotificationsProviderStub(); } } @Override public void register() { provider.register(); } @Override public void unregister() { provider.unregister(); } @NonNull @Override
public AvailabilityResult getAvailabilityResult() {
onepf/OPFPush
opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaNotificationsProvider.java
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // } // // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaPushConstants.java // static final String NOKIA_MANUFACTURER = "Nokia";
import android.content.Context; import android.os.Build; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker; import org.onepf.opfutils.OPFLog; import static org.onepf.opfpush.nokia.NokiaPushConstants.NOKIA_MANUFACTURER;
@Override public boolean isRegistered() { return provider.isRegistered(); } @Nullable @Override public String getRegistrationId() { return provider.getRegistrationId(); } @NonNull @Override public String getName() { return provider.getName(); } @Nullable @Override public String getHostAppPackage() { return provider.getHostAppPackage(); } @NonNull @Override public NotificationMaker getNotificationMaker() { return provider.getNotificationMaker(); } @Override
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // } // // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaPushConstants.java // static final String NOKIA_MANUFACTURER = "Nokia"; // Path: opfpush-providers/nokia/src/main/java/org/onepf/opfpush/nokia/NokiaNotificationsProvider.java import android.content.Context; import android.os.Build; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker; import org.onepf.opfutils.OPFLog; import static org.onepf.opfpush.nokia.NokiaPushConstants.NOKIA_MANUFACTURER; @Override public boolean isRegistered() { return provider.isRegistered(); } @Nullable @Override public String getRegistrationId() { return provider.getRegistrationId(); } @NonNull @Override public String getName() { return provider.getName(); } @Nullable @Override public String getHostAppPackage() { return provider.getHostAppPackage(); } @NonNull @Override public NotificationMaker getNotificationMaker() { return provider.getNotificationMaker(); } @Override
public void checkManifest(@Nullable final CheckManifestHandler checkManifestHandler) {
onepf/OPFPush
opfpush/src/main/java/org/onepf/opfpush/pushprovider/PushProvider.java
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // }
import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.pushprovider; /** * The {@code PushProvider} interface represent the provider for push notification from the server to * the client app. * <p/> * The {@link #register()} and {@link #unregister()} methods intended for the internal use, * should never be called directly. * Use {@link org.onepf.opfpush.OPFPushHelper#register()} or {@link org.onepf.opfpush.OPFPushHelper#unregister()} to start registration * or unregistration. * * @author Anton Rutkevich, Alexey Vitenko, Kirill Rozov * @since 14.05.14 */ public interface PushProvider { /** * Initiates the registration of the provider. Must be async. * <p/> * Intended for the internal use, should never be called directly. * To start the registration call {@link org.onepf.opfpush.OPFPushHelper#register()}. */ void register(); /** * Initiates the unregistering of the provider. Must be async. * <p/> * Intended for internal use, should never be called directly. * To start registration call {@link org.onepf.opfpush.OPFPushHelper#unregister()}. */ void unregister(); /** * Checks whether the provider is available. * * @return The instance of {@link org.onepf.opfpush.model.AvailabilityResult} * that contains result of availability check. */ @NonNull
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // } // Path: opfpush/src/main/java/org/onepf/opfpush/pushprovider/PushProvider.java import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.pushprovider; /** * The {@code PushProvider} interface represent the provider for push notification from the server to * the client app. * <p/> * The {@link #register()} and {@link #unregister()} methods intended for the internal use, * should never be called directly. * Use {@link org.onepf.opfpush.OPFPushHelper#register()} or {@link org.onepf.opfpush.OPFPushHelper#unregister()} to start registration * or unregistration. * * @author Anton Rutkevich, Alexey Vitenko, Kirill Rozov * @since 14.05.14 */ public interface PushProvider { /** * Initiates the registration of the provider. Must be async. * <p/> * Intended for the internal use, should never be called directly. * To start the registration call {@link org.onepf.opfpush.OPFPushHelper#register()}. */ void register(); /** * Initiates the unregistering of the provider. Must be async. * <p/> * Intended for internal use, should never be called directly. * To start registration call {@link org.onepf.opfpush.OPFPushHelper#unregister()}. */ void unregister(); /** * Checks whether the provider is available. * * @return The instance of {@link org.onepf.opfpush.model.AvailabilityResult} * that contains result of availability check. */ @NonNull
AvailabilityResult getAvailabilityResult();
onepf/OPFPush
opfpush/src/main/java/org/onepf/opfpush/pushprovider/PushProvider.java
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // }
import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.pushprovider; /** * The {@code PushProvider} interface represent the provider for push notification from the server to * the client app. * <p/> * The {@link #register()} and {@link #unregister()} methods intended for the internal use, * should never be called directly. * Use {@link org.onepf.opfpush.OPFPushHelper#register()} or {@link org.onepf.opfpush.OPFPushHelper#unregister()} to start registration * or unregistration. * * @author Anton Rutkevich, Alexey Vitenko, Kirill Rozov * @since 14.05.14 */ public interface PushProvider { /** * Initiates the registration of the provider. Must be async. * <p/> * Intended for the internal use, should never be called directly. * To start the registration call {@link org.onepf.opfpush.OPFPushHelper#register()}. */ void register(); /** * Initiates the unregistering of the provider. Must be async. * <p/> * Intended for internal use, should never be called directly. * To start registration call {@link org.onepf.opfpush.OPFPushHelper#unregister()}. */ void unregister(); /** * Checks whether the provider is available. * * @return The instance of {@link org.onepf.opfpush.model.AvailabilityResult} * that contains result of availability check. */ @NonNull AvailabilityResult getAvailabilityResult(); /** * Checks whether the application was successfully registered on the service. * * @return {@code true} if the application was successfully registered on the service, otherwise false. */ boolean isRegistered(); /** * Returns the registration ID or null if provider isn't registered. * * @return The registration ID or null if provider isn't registered. */ @Nullable String getRegistrationId(); /** * Returns the name of the provider. Must be unique for all providers. * * @return The name of the provider. */ @NonNull String getName(); /** * Returns the package of the application that contains API of the provider. * Usually, this is a store application. * * @return The package of the application that contains API of the provider. */ @Nullable String getHostAppPackage(); /** * Returns the {@link NotificationMaker} object associated with provider. * * @return The {@link NotificationMaker} instance. */ @NonNull
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // } // Path: opfpush/src/main/java/org/onepf/opfpush/pushprovider/PushProvider.java import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.pushprovider; /** * The {@code PushProvider} interface represent the provider for push notification from the server to * the client app. * <p/> * The {@link #register()} and {@link #unregister()} methods intended for the internal use, * should never be called directly. * Use {@link org.onepf.opfpush.OPFPushHelper#register()} or {@link org.onepf.opfpush.OPFPushHelper#unregister()} to start registration * or unregistration. * * @author Anton Rutkevich, Alexey Vitenko, Kirill Rozov * @since 14.05.14 */ public interface PushProvider { /** * Initiates the registration of the provider. Must be async. * <p/> * Intended for the internal use, should never be called directly. * To start the registration call {@link org.onepf.opfpush.OPFPushHelper#register()}. */ void register(); /** * Initiates the unregistering of the provider. Must be async. * <p/> * Intended for internal use, should never be called directly. * To start registration call {@link org.onepf.opfpush.OPFPushHelper#unregister()}. */ void unregister(); /** * Checks whether the provider is available. * * @return The instance of {@link org.onepf.opfpush.model.AvailabilityResult} * that contains result of availability check. */ @NonNull AvailabilityResult getAvailabilityResult(); /** * Checks whether the application was successfully registered on the service. * * @return {@code true} if the application was successfully registered on the service, otherwise false. */ boolean isRegistered(); /** * Returns the registration ID or null if provider isn't registered. * * @return The registration ID or null if provider isn't registered. */ @Nullable String getRegistrationId(); /** * Returns the name of the provider. Must be unique for all providers. * * @return The name of the provider. */ @NonNull String getName(); /** * Returns the package of the application that contains API of the provider. * Usually, this is a store application. * * @return The package of the application that contains API of the provider. */ @Nullable String getHostAppPackage(); /** * Returns the {@link NotificationMaker} object associated with provider. * * @return The {@link NotificationMaker} instance. */ @NonNull
NotificationMaker getNotificationMaker();
onepf/OPFPush
opfpush/src/main/java/org/onepf/opfpush/pushprovider/PushProvider.java
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // }
import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker;
/* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.pushprovider; /** * The {@code PushProvider} interface represent the provider for push notification from the server to * the client app. * <p/> * The {@link #register()} and {@link #unregister()} methods intended for the internal use, * should never be called directly. * Use {@link org.onepf.opfpush.OPFPushHelper#register()} or {@link org.onepf.opfpush.OPFPushHelper#unregister()} to start registration * or unregistration. * * @author Anton Rutkevich, Alexey Vitenko, Kirill Rozov * @since 14.05.14 */ public interface PushProvider { /** * Initiates the registration of the provider. Must be async. * <p/> * Intended for the internal use, should never be called directly. * To start the registration call {@link org.onepf.opfpush.OPFPushHelper#register()}. */ void register(); /** * Initiates the unregistering of the provider. Must be async. * <p/> * Intended for internal use, should never be called directly. * To start registration call {@link org.onepf.opfpush.OPFPushHelper#unregister()}. */ void unregister(); /** * Checks whether the provider is available. * * @return The instance of {@link org.onepf.opfpush.model.AvailabilityResult} * that contains result of availability check. */ @NonNull AvailabilityResult getAvailabilityResult(); /** * Checks whether the application was successfully registered on the service. * * @return {@code true} if the application was successfully registered on the service, otherwise false. */ boolean isRegistered(); /** * Returns the registration ID or null if provider isn't registered. * * @return The registration ID or null if provider isn't registered. */ @Nullable String getRegistrationId(); /** * Returns the name of the provider. Must be unique for all providers. * * @return The name of the provider. */ @NonNull String getName(); /** * Returns the package of the application that contains API of the provider. * Usually, this is a store application. * * @return The package of the application that contains API of the provider. */ @Nullable String getHostAppPackage(); /** * Returns the {@link NotificationMaker} object associated with provider. * * @return The {@link NotificationMaker} instance. */ @NonNull NotificationMaker getNotificationMaker(); /** * Verify that application manifest contains all needed permissions. * * @param checkManifestHandler If not null an exception isn't thrown. * @throws java.lang.IllegalStateException If not all required permissions and components have been * described in the AndroidManifest.xml file. */
// Path: opfpush/src/main/java/org/onepf/opfpush/listener/CheckManifestHandler.java // public interface CheckManifestHandler { // // /** // * Called when some check manifest error occurred. // * // * @param reportMessage The information about error. // */ // void onCheckManifestError(@NonNull final String reportMessage); // } // // Path: opfpush/src/main/java/org/onepf/opfpush/model/AvailabilityResult.java // public final class AvailabilityResult { // // private boolean isAvailable; // // @Nullable // private Integer errorCode; // // public AvailabilityResult(final boolean isAvailable) { // this(isAvailable, null); // } // // public AvailabilityResult(@NonNull final Integer errorCode) { // this(false, errorCode); // } // // public AvailabilityResult(final boolean isAvailable, @Nullable final Integer errorCode) { // this.isAvailable = isAvailable; // this.errorCode = errorCode; // } // // /** // * Returns {@code true} if a provider is available, false otherwise. // * // * @return {@code true} if a provider is available, false otherwise. // */ // public boolean isAvailable() { // return isAvailable; // } // // /** // * Returns a specific provider error code. // * // * @return The availability error code, or {@code null} if a provider hasn't returned a error code. // */ // @Nullable // public Integer getErrorCode() { // return errorCode; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/notification/NotificationMaker.java // public interface NotificationMaker { // // /** // * Returns true if a notification must be shown for the bundle. False otherwise. // * // * @param bundle The bundle received from a push provider. // * @return Returns true if a notification should be shown for the bundle. False otherwise. // */ // boolean needShowNotification(@NonNull final Bundle bundle); // // /** // * Shows notification using bundle data. // * // * @param context The Context instance. // * @param bundle Received data. // */ // void showNotification(@NonNull final Context context, @NonNull final Bundle bundle); // } // Path: opfpush/src/main/java/org/onepf/opfpush/pushprovider/PushProvider.java import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.onepf.opfpush.listener.CheckManifestHandler; import org.onepf.opfpush.model.AvailabilityResult; import org.onepf.opfpush.notification.NotificationMaker; /* * Copyright 2012-2015 One Platform Foundation * * 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 org.onepf.opfpush.pushprovider; /** * The {@code PushProvider} interface represent the provider for push notification from the server to * the client app. * <p/> * The {@link #register()} and {@link #unregister()} methods intended for the internal use, * should never be called directly. * Use {@link org.onepf.opfpush.OPFPushHelper#register()} or {@link org.onepf.opfpush.OPFPushHelper#unregister()} to start registration * or unregistration. * * @author Anton Rutkevich, Alexey Vitenko, Kirill Rozov * @since 14.05.14 */ public interface PushProvider { /** * Initiates the registration of the provider. Must be async. * <p/> * Intended for the internal use, should never be called directly. * To start the registration call {@link org.onepf.opfpush.OPFPushHelper#register()}. */ void register(); /** * Initiates the unregistering of the provider. Must be async. * <p/> * Intended for internal use, should never be called directly. * To start registration call {@link org.onepf.opfpush.OPFPushHelper#unregister()}. */ void unregister(); /** * Checks whether the provider is available. * * @return The instance of {@link org.onepf.opfpush.model.AvailabilityResult} * that contains result of availability check. */ @NonNull AvailabilityResult getAvailabilityResult(); /** * Checks whether the application was successfully registered on the service. * * @return {@code true} if the application was successfully registered on the service, otherwise false. */ boolean isRegistered(); /** * Returns the registration ID or null if provider isn't registered. * * @return The registration ID or null if provider isn't registered. */ @Nullable String getRegistrationId(); /** * Returns the name of the provider. Must be unique for all providers. * * @return The name of the provider. */ @NonNull String getName(); /** * Returns the package of the application that contains API of the provider. * Usually, this is a store application. * * @return The package of the application that contains API of the provider. */ @Nullable String getHostAppPackage(); /** * Returns the {@link NotificationMaker} object associated with provider. * * @return The {@link NotificationMaker} instance. */ @NonNull NotificationMaker getNotificationMaker(); /** * Verify that application manifest contains all needed permissions. * * @param checkManifestHandler If not null an exception isn't thrown. * @throws java.lang.IllegalStateException If not all required permissions and components have been * described in the AndroidManifest.xml file. */
void checkManifest(@Nullable CheckManifestHandler checkManifestHandler);
onepf/OPFPush
opfpush/src/test/java/org/onepf/opfpush/testutil/Util.java
// Path: opfpush/src/test/java/org/onepf/opfpush/mock/MockNamePushProvider.java // public class MockNamePushProvider extends BasePushProvider { // // public static final String DEFAULT_HOST_APP_PACKAGE = "org.onepf.store"; // // public MockNamePushProvider(@NonNull String name) { // this(name, DEFAULT_HOST_APP_PACKAGE); // } // // public MockNamePushProvider(@NonNull String name, // @NonNull String hostAppPackage) { // super(RuntimeEnvironment.application, name, hostAppPackage); // } // // @Override // public void register() { // //nothing // } // // @Override // public void unregister() { // //nothing // } // // @Override // public void onRegistrationInvalid() { // //nothing // } // // @Override // public void onUnavailable() { // //nothing // } // // @Override // public boolean isRegistered() { // return false; // } // // @Nullable // @Override // public String getRegistrationId() { // return null; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/pushprovider/PushProvider.java // public interface PushProvider { // /** // * Initiates the registration of the provider. Must be async. // * <p/> // * Intended for the internal use, should never be called directly. // * To start the registration call {@link org.onepf.opfpush.OPFPushHelper#register()}. // */ // void register(); // // /** // * Initiates the unregistering of the provider. Must be async. // * <p/> // * Intended for internal use, should never be called directly. // * To start registration call {@link org.onepf.opfpush.OPFPushHelper#unregister()}. // */ // void unregister(); // // /** // * Checks whether the provider is available. // * // * @return The instance of {@link org.onepf.opfpush.model.AvailabilityResult} // * that contains result of availability check. // */ // @NonNull // AvailabilityResult getAvailabilityResult(); // // /** // * Checks whether the application was successfully registered on the service. // * // * @return {@code true} if the application was successfully registered on the service, otherwise false. // */ // boolean isRegistered(); // // /** // * Returns the registration ID or null if provider isn't registered. // * // * @return The registration ID or null if provider isn't registered. // */ // @Nullable // String getRegistrationId(); // // /** // * Returns the name of the provider. Must be unique for all providers. // * // * @return The name of the provider. // */ // @NonNull // String getName(); // // /** // * Returns the package of the application that contains API of the provider. // * Usually, this is a store application. // * // * @return The package of the application that contains API of the provider. // */ // @Nullable // String getHostAppPackage(); // // /** // * Returns the {@link NotificationMaker} object associated with provider. // * // * @return The {@link NotificationMaker} instance. // */ // @NonNull // NotificationMaker getNotificationMaker(); // // /** // * Verify that application manifest contains all needed permissions. // * // * @param checkManifestHandler If not null an exception isn't thrown. // * @throws java.lang.IllegalStateException If not all required permissions and components have been // * described in the AndroidManifest.xml file. // */ // void checkManifest(@Nullable CheckManifestHandler checkManifestHandler); // // /** // * Callback method, that called when the application state change, like update to new version, // * or system state changed, like update firmware to a newer version. // * <p/> // * If this method is called, your registration becomes invalid // * and you have to reset all saved registration data. // */ // void onRegistrationInvalid(); // // /** // * Callback method for notify that the provider became unavailable. // * In this method you have to reset all saved registration data. // */ // void onUnavailable(); // }
import org.onepf.opfpush.mock.MockNamePushProvider; import org.onepf.opfpush.pushprovider.PushProvider; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Random;
package org.onepf.opfpush.testutil; /** * @author antonpp * @since 13.04.15 */ public final class Util { public static final int NUM_TESTS = 100; public static final int NUM_PROVIDERS = 100; public static final int RANDOM_STRING_LENGTH = 16; private static final Random RND = new Random(); private Util() { throw new UnsupportedOperationException(); } public static List<String> shuffleStringArray(final String[] array) { final List<String> mixedArray = Arrays.asList(array); Collections.shuffle(mixedArray); return mixedArray; } public static String[] getRandomStrings(int n, int len) { char[] chars = "abcdefghijklmnopqrstuvwxyz0123456789".toCharArray(); String[] strings = new String[n]; for (int i = 0; i < n; ++i) { StringBuilder sb = new StringBuilder(); for (int j = 0; j < len; j++) { char c = chars[RND.nextInt(chars.length)]; sb.append(c); } strings[i] = sb.toString(); } return strings; }
// Path: opfpush/src/test/java/org/onepf/opfpush/mock/MockNamePushProvider.java // public class MockNamePushProvider extends BasePushProvider { // // public static final String DEFAULT_HOST_APP_PACKAGE = "org.onepf.store"; // // public MockNamePushProvider(@NonNull String name) { // this(name, DEFAULT_HOST_APP_PACKAGE); // } // // public MockNamePushProvider(@NonNull String name, // @NonNull String hostAppPackage) { // super(RuntimeEnvironment.application, name, hostAppPackage); // } // // @Override // public void register() { // //nothing // } // // @Override // public void unregister() { // //nothing // } // // @Override // public void onRegistrationInvalid() { // //nothing // } // // @Override // public void onUnavailable() { // //nothing // } // // @Override // public boolean isRegistered() { // return false; // } // // @Nullable // @Override // public String getRegistrationId() { // return null; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/pushprovider/PushProvider.java // public interface PushProvider { // /** // * Initiates the registration of the provider. Must be async. // * <p/> // * Intended for the internal use, should never be called directly. // * To start the registration call {@link org.onepf.opfpush.OPFPushHelper#register()}. // */ // void register(); // // /** // * Initiates the unregistering of the provider. Must be async. // * <p/> // * Intended for internal use, should never be called directly. // * To start registration call {@link org.onepf.opfpush.OPFPushHelper#unregister()}. // */ // void unregister(); // // /** // * Checks whether the provider is available. // * // * @return The instance of {@link org.onepf.opfpush.model.AvailabilityResult} // * that contains result of availability check. // */ // @NonNull // AvailabilityResult getAvailabilityResult(); // // /** // * Checks whether the application was successfully registered on the service. // * // * @return {@code true} if the application was successfully registered on the service, otherwise false. // */ // boolean isRegistered(); // // /** // * Returns the registration ID or null if provider isn't registered. // * // * @return The registration ID or null if provider isn't registered. // */ // @Nullable // String getRegistrationId(); // // /** // * Returns the name of the provider. Must be unique for all providers. // * // * @return The name of the provider. // */ // @NonNull // String getName(); // // /** // * Returns the package of the application that contains API of the provider. // * Usually, this is a store application. // * // * @return The package of the application that contains API of the provider. // */ // @Nullable // String getHostAppPackage(); // // /** // * Returns the {@link NotificationMaker} object associated with provider. // * // * @return The {@link NotificationMaker} instance. // */ // @NonNull // NotificationMaker getNotificationMaker(); // // /** // * Verify that application manifest contains all needed permissions. // * // * @param checkManifestHandler If not null an exception isn't thrown. // * @throws java.lang.IllegalStateException If not all required permissions and components have been // * described in the AndroidManifest.xml file. // */ // void checkManifest(@Nullable CheckManifestHandler checkManifestHandler); // // /** // * Callback method, that called when the application state change, like update to new version, // * or system state changed, like update firmware to a newer version. // * <p/> // * If this method is called, your registration becomes invalid // * and you have to reset all saved registration data. // */ // void onRegistrationInvalid(); // // /** // * Callback method for notify that the provider became unavailable. // * In this method you have to reset all saved registration data. // */ // void onUnavailable(); // } // Path: opfpush/src/test/java/org/onepf/opfpush/testutil/Util.java import org.onepf.opfpush.mock.MockNamePushProvider; import org.onepf.opfpush.pushprovider.PushProvider; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Random; package org.onepf.opfpush.testutil; /** * @author antonpp * @since 13.04.15 */ public final class Util { public static final int NUM_TESTS = 100; public static final int NUM_PROVIDERS = 100; public static final int RANDOM_STRING_LENGTH = 16; private static final Random RND = new Random(); private Util() { throw new UnsupportedOperationException(); } public static List<String> shuffleStringArray(final String[] array) { final List<String> mixedArray = Arrays.asList(array); Collections.shuffle(mixedArray); return mixedArray; } public static String[] getRandomStrings(int n, int len) { char[] chars = "abcdefghijklmnopqrstuvwxyz0123456789".toCharArray(); String[] strings = new String[n]; for (int i = 0; i < n; ++i) { StringBuilder sb = new StringBuilder(); for (int j = 0; j < len; j++) { char c = chars[RND.nextInt(chars.length)]; sb.append(c); } strings[i] = sb.toString(); } return strings; }
public static PushProvider[] getRandomPushProviders() {
onepf/OPFPush
opfpush/src/test/java/org/onepf/opfpush/testutil/Util.java
// Path: opfpush/src/test/java/org/onepf/opfpush/mock/MockNamePushProvider.java // public class MockNamePushProvider extends BasePushProvider { // // public static final String DEFAULT_HOST_APP_PACKAGE = "org.onepf.store"; // // public MockNamePushProvider(@NonNull String name) { // this(name, DEFAULT_HOST_APP_PACKAGE); // } // // public MockNamePushProvider(@NonNull String name, // @NonNull String hostAppPackage) { // super(RuntimeEnvironment.application, name, hostAppPackage); // } // // @Override // public void register() { // //nothing // } // // @Override // public void unregister() { // //nothing // } // // @Override // public void onRegistrationInvalid() { // //nothing // } // // @Override // public void onUnavailable() { // //nothing // } // // @Override // public boolean isRegistered() { // return false; // } // // @Nullable // @Override // public String getRegistrationId() { // return null; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/pushprovider/PushProvider.java // public interface PushProvider { // /** // * Initiates the registration of the provider. Must be async. // * <p/> // * Intended for the internal use, should never be called directly. // * To start the registration call {@link org.onepf.opfpush.OPFPushHelper#register()}. // */ // void register(); // // /** // * Initiates the unregistering of the provider. Must be async. // * <p/> // * Intended for internal use, should never be called directly. // * To start registration call {@link org.onepf.opfpush.OPFPushHelper#unregister()}. // */ // void unregister(); // // /** // * Checks whether the provider is available. // * // * @return The instance of {@link org.onepf.opfpush.model.AvailabilityResult} // * that contains result of availability check. // */ // @NonNull // AvailabilityResult getAvailabilityResult(); // // /** // * Checks whether the application was successfully registered on the service. // * // * @return {@code true} if the application was successfully registered on the service, otherwise false. // */ // boolean isRegistered(); // // /** // * Returns the registration ID or null if provider isn't registered. // * // * @return The registration ID or null if provider isn't registered. // */ // @Nullable // String getRegistrationId(); // // /** // * Returns the name of the provider. Must be unique for all providers. // * // * @return The name of the provider. // */ // @NonNull // String getName(); // // /** // * Returns the package of the application that contains API of the provider. // * Usually, this is a store application. // * // * @return The package of the application that contains API of the provider. // */ // @Nullable // String getHostAppPackage(); // // /** // * Returns the {@link NotificationMaker} object associated with provider. // * // * @return The {@link NotificationMaker} instance. // */ // @NonNull // NotificationMaker getNotificationMaker(); // // /** // * Verify that application manifest contains all needed permissions. // * // * @param checkManifestHandler If not null an exception isn't thrown. // * @throws java.lang.IllegalStateException If not all required permissions and components have been // * described in the AndroidManifest.xml file. // */ // void checkManifest(@Nullable CheckManifestHandler checkManifestHandler); // // /** // * Callback method, that called when the application state change, like update to new version, // * or system state changed, like update firmware to a newer version. // * <p/> // * If this method is called, your registration becomes invalid // * and you have to reset all saved registration data. // */ // void onRegistrationInvalid(); // // /** // * Callback method for notify that the provider became unavailable. // * In this method you have to reset all saved registration data. // */ // void onUnavailable(); // }
import org.onepf.opfpush.mock.MockNamePushProvider; import org.onepf.opfpush.pushprovider.PushProvider; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Random;
package org.onepf.opfpush.testutil; /** * @author antonpp * @since 13.04.15 */ public final class Util { public static final int NUM_TESTS = 100; public static final int NUM_PROVIDERS = 100; public static final int RANDOM_STRING_LENGTH = 16; private static final Random RND = new Random(); private Util() { throw new UnsupportedOperationException(); } public static List<String> shuffleStringArray(final String[] array) { final List<String> mixedArray = Arrays.asList(array); Collections.shuffle(mixedArray); return mixedArray; } public static String[] getRandomStrings(int n, int len) { char[] chars = "abcdefghijklmnopqrstuvwxyz0123456789".toCharArray(); String[] strings = new String[n]; for (int i = 0; i < n; ++i) { StringBuilder sb = new StringBuilder(); for (int j = 0; j < len; j++) { char c = chars[RND.nextInt(chars.length)]; sb.append(c); } strings[i] = sb.toString(); } return strings; } public static PushProvider[] getRandomPushProviders() {
// Path: opfpush/src/test/java/org/onepf/opfpush/mock/MockNamePushProvider.java // public class MockNamePushProvider extends BasePushProvider { // // public static final String DEFAULT_HOST_APP_PACKAGE = "org.onepf.store"; // // public MockNamePushProvider(@NonNull String name) { // this(name, DEFAULT_HOST_APP_PACKAGE); // } // // public MockNamePushProvider(@NonNull String name, // @NonNull String hostAppPackage) { // super(RuntimeEnvironment.application, name, hostAppPackage); // } // // @Override // public void register() { // //nothing // } // // @Override // public void unregister() { // //nothing // } // // @Override // public void onRegistrationInvalid() { // //nothing // } // // @Override // public void onUnavailable() { // //nothing // } // // @Override // public boolean isRegistered() { // return false; // } // // @Nullable // @Override // public String getRegistrationId() { // return null; // } // } // // Path: opfpush/src/main/java/org/onepf/opfpush/pushprovider/PushProvider.java // public interface PushProvider { // /** // * Initiates the registration of the provider. Must be async. // * <p/> // * Intended for the internal use, should never be called directly. // * To start the registration call {@link org.onepf.opfpush.OPFPushHelper#register()}. // */ // void register(); // // /** // * Initiates the unregistering of the provider. Must be async. // * <p/> // * Intended for internal use, should never be called directly. // * To start registration call {@link org.onepf.opfpush.OPFPushHelper#unregister()}. // */ // void unregister(); // // /** // * Checks whether the provider is available. // * // * @return The instance of {@link org.onepf.opfpush.model.AvailabilityResult} // * that contains result of availability check. // */ // @NonNull // AvailabilityResult getAvailabilityResult(); // // /** // * Checks whether the application was successfully registered on the service. // * // * @return {@code true} if the application was successfully registered on the service, otherwise false. // */ // boolean isRegistered(); // // /** // * Returns the registration ID or null if provider isn't registered. // * // * @return The registration ID or null if provider isn't registered. // */ // @Nullable // String getRegistrationId(); // // /** // * Returns the name of the provider. Must be unique for all providers. // * // * @return The name of the provider. // */ // @NonNull // String getName(); // // /** // * Returns the package of the application that contains API of the provider. // * Usually, this is a store application. // * // * @return The package of the application that contains API of the provider. // */ // @Nullable // String getHostAppPackage(); // // /** // * Returns the {@link NotificationMaker} object associated with provider. // * // * @return The {@link NotificationMaker} instance. // */ // @NonNull // NotificationMaker getNotificationMaker(); // // /** // * Verify that application manifest contains all needed permissions. // * // * @param checkManifestHandler If not null an exception isn't thrown. // * @throws java.lang.IllegalStateException If not all required permissions and components have been // * described in the AndroidManifest.xml file. // */ // void checkManifest(@Nullable CheckManifestHandler checkManifestHandler); // // /** // * Callback method, that called when the application state change, like update to new version, // * or system state changed, like update firmware to a newer version. // * <p/> // * If this method is called, your registration becomes invalid // * and you have to reset all saved registration data. // */ // void onRegistrationInvalid(); // // /** // * Callback method for notify that the provider became unavailable. // * In this method you have to reset all saved registration data. // */ // void onUnavailable(); // } // Path: opfpush/src/test/java/org/onepf/opfpush/testutil/Util.java import org.onepf.opfpush.mock.MockNamePushProvider; import org.onepf.opfpush.pushprovider.PushProvider; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Random; package org.onepf.opfpush.testutil; /** * @author antonpp * @since 13.04.15 */ public final class Util { public static final int NUM_TESTS = 100; public static final int NUM_PROVIDERS = 100; public static final int RANDOM_STRING_LENGTH = 16; private static final Random RND = new Random(); private Util() { throw new UnsupportedOperationException(); } public static List<String> shuffleStringArray(final String[] array) { final List<String> mixedArray = Arrays.asList(array); Collections.shuffle(mixedArray); return mixedArray; } public static String[] getRandomStrings(int n, int len) { char[] chars = "abcdefghijklmnopqrstuvwxyz0123456789".toCharArray(); String[] strings = new String[n]; for (int i = 0; i < n; ++i) { StringBuilder sb = new StringBuilder(); for (int j = 0; j < len; j++) { char c = chars[RND.nextInt(chars.length)]; sb.append(c); } strings[i] = sb.toString(); } return strings; } public static PushProvider[] getRandomPushProviders() {
final MockNamePushProvider[] pushProviders = new MockNamePushProvider[NUM_PROVIDERS];