blob: 8468515f367e9d1ea4f058e1bf22c85e23eaad58 [file] [log] [blame]
Kim Hansen086964d2013-12-10 11:33:28 +00001/*
2 * Copyright (C) 2013 Fairphone Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jose Pascoal7bf83a02014-10-13 18:30:18 +010017package com.fairphone.updater.data;
Kim Hansen086964d2013-12-10 11:33:28 +000018
Kim Hansen086964d2013-12-10 11:33:28 +000019import android.content.res.Resources;
20import android.text.TextUtils;
Jose Pascoal40916302015-02-06 18:43:47 +000021import android.util.Log;
Kim Hansen086964d2013-12-10 11:33:28 +000022
Jose Pascoal8a31c8d2014-10-17 17:05:29 +010023import com.fairphone.updater.R;
24
Filipe Gonçalves4c204d82015-01-23 15:09:19 +000025import java.util.ArrayList;
Jose Pascoal40916302015-02-06 18:43:47 +000026import java.util.List;
Filipe Gonçalves4c204d82015-01-23 15:09:19 +000027
Tiago Costa6d360e22014-12-15 14:32:51 +000028public class Version extends DownloadableItem implements Comparable<Version>
Jose Pascoal810950b2014-10-09 17:16:08 +010029{
Jose Pascoal40916302015-02-06 18:43:47 +000030 private static final String TAG = Version.class.getSimpleName();
31
32 private static final String DEPENDENCY_SEPARATOR = ",";
Kim Hansen086964d2013-12-10 11:33:28 +000033
Jose Pascoal1ee56e22014-05-21 16:58:20 +010034 public static final String IMAGE_TYPE_AOSP = "AOSP";
Kim Hansen086964d2013-12-10 11:33:28 +000035
Jose Pascoal1ee56e22014-05-21 16:58:20 +010036 public static final String IMAGE_TYPE_FAIRPHONE = "FAIRPHONE";
Kim Hansen086964d2013-12-10 11:33:28 +000037
Filipe Gonçalvesb31d5862015-02-04 17:28:58 +000038 private String mImageType;
Kim Hansen086964d2013-12-10 11:33:28 +000039
Filipe Gonçalvesb31d5862015-02-04 17:28:58 +000040 private String mAndroidVersion;
Kim Hansen086964d2013-12-10 11:33:28 +000041
Filipe Gonçalvesb31d5862015-02-04 17:28:58 +000042 private String mBetaStatus;
Filipe Gonçalves4c204d82015-01-23 15:09:19 +000043
Filipe Gonçalvesb31d5862015-02-04 17:28:58 +000044 private boolean mErasePartitionsWarning;
Jose Pascoal810950b2014-10-09 17:16:08 +010045
Jose Pascoalcfc2dd42015-02-09 18:00:05 +000046 private final List<Integer> mDependencies;
Jose Pascoal40916302015-02-06 18:43:47 +000047
Maarten Derksbb287762015-10-12 17:22:45 +020048 public static final String ZIP_INSTALL_VERSION = "999";
Jose Pascoal79357c52015-03-12 20:14:29 +000049
Jose Pascoal810950b2014-10-09 17:16:08 +010050 public Version()
51 {
Jose Pascoal40916302015-02-06 18:43:47 +000052 super();
Filipe Gonçalvesb31d5862015-02-04 17:28:58 +000053 mDependencies = new ArrayList<>();
Jose Pascoal2666b892014-10-02 21:05:08 +010054 mAndroidVersion = "";
Jose Pascoal2666b892014-10-02 21:05:08 +010055 mImageType = IMAGE_TYPE_FAIRPHONE;
Jose Pascoalcfc2dd42015-02-09 18:00:05 +000056 mErasePartitionsWarning = false;
Filipe Gonçalves4c204d82015-01-23 15:09:19 +000057 mBetaStatus = "";
Jose Pascoal1ee56e22014-05-21 16:58:20 +010058 }
Kim Hansen086964d2013-12-10 11:33:28 +000059
Jose Pascoal060ab282015-02-09 19:56:08 +000060 public Version(Version other)
61 {
62 super(other);
63 mDependencies = other.mDependencies;
64 mAndroidVersion = other.mAndroidVersion;
65 mImageType = other.mImageType;
66 mErasePartitionsWarning = other.hasEraseAllPartitionWarning();
67 mBetaStatus = other.mBetaStatus;
68 }
69
Jose Pascoalcfc2dd42015-02-09 18:00:05 +000070 public void setEraseAllPartitionWarning()
Jose Pascoal810950b2014-10-09 17:16:08 +010071 {
Jose Pascoalcfc2dd42015-02-09 18:00:05 +000072 mErasePartitionsWarning = true;
Tiago Costa554587b2014-06-26 18:39:40 +010073 }
Jose Pascoal810950b2014-10-09 17:16:08 +010074
Tiago Costa6d360e22014-12-15 14:32:51 +000075 public boolean hasEraseAllPartitionWarning()
Jose Pascoal810950b2014-10-09 17:16:08 +010076 {
Tiago Costa6d360e22014-12-15 14:32:51 +000077 return mErasePartitionsWarning;
Jose Pascoal1ee56e22014-05-21 16:58:20 +010078 }
Jose Pascoal9be8f0d2014-03-10 11:22:41 +000079
Tiago Costa6d360e22014-12-15 14:32:51 +000080 public String getAndroidVersion()
Jose Pascoal810950b2014-10-09 17:16:08 +010081 {
Tiago Costa6d360e22014-12-15 14:32:51 +000082 return mAndroidVersion;
Jose Pascoal1ee56e22014-05-21 16:58:20 +010083 }
84
Tiago Costa6d360e22014-12-15 14:32:51 +000085 public void setAndroidVersion(String mAndroid)
Jose Pascoal810950b2014-10-09 17:16:08 +010086 {
Tiago Costa6d360e22014-12-15 14:32:51 +000087 this.mAndroidVersion = mAndroid;
Jose Pascoal1ee56e22014-05-21 16:58:20 +010088 }
89
Jose Pascoal810950b2014-10-09 17:16:08 +010090 public void setImageType(String imageType)
91 {
Jose Pascoal1ee56e22014-05-21 16:58:20 +010092 mImageType = imageType;
93 }
94
Jose Pascoal810950b2014-10-09 17:16:08 +010095 public String getImageType()
96 {
Jose Pascoal1ee56e22014-05-21 16:58:20 +010097 return mImageType;
98 }
Jose Pascoal810950b2014-10-09 17:16:08 +010099
Filipe Gonçalves4c204d82015-01-23 15:09:19 +0000100 public void setBetaStatus(String betaStatus)
101 {
102 mBetaStatus = betaStatus;
103 }
104
105 public String getBetaStatus()
106 {
107 return mBetaStatus;
108 }
109
Jose Pascoal810950b2014-10-09 17:16:08 +0100110 public String getImageTypeDescription(Resources resources)
111 {
Jose Pascoala8604492014-06-23 19:12:08 +0100112 return Version.getImageTypeDescription(mImageType, resources);
Jose Pascoal1ee56e22014-05-21 16:58:20 +0100113 }
Jose Pascoal810950b2014-10-09 17:16:08 +0100114
Filipe Gonçalvesb31d5862015-02-04 17:28:58 +0000115 private static String getImageTypeDescription(String imageType, Resources resources)
Jose Pascoal810950b2014-10-09 17:16:08 +0100116 {
Jose Pascoal1ee56e22014-05-21 16:58:20 +0100117 String description = resources.getString(R.string.fairphone);
Jose Pascoalaa579a82014-11-05 22:17:16 +0000118 if (!TextUtils.isEmpty(imageType))
Jose Pascoal810950b2014-10-09 17:16:08 +0100119 {
Jose Pascoalaa579a82014-11-05 22:17:16 +0000120 if (imageType.equalsIgnoreCase(IMAGE_TYPE_AOSP))
121 {
122 description = resources.getString(R.string.android);
123 }
124 if (imageType.equalsIgnoreCase(IMAGE_TYPE_FAIRPHONE))
125 {
126 description = resources.getString(R.string.fairphone);
127 }
Jose Pascoal1ee56e22014-05-21 16:58:20 +0100128 }
129 return description;
130 }
Jose Pascoal810950b2014-10-09 17:16:08 +0100131
Jose Pascoalcdd82042015-02-06 13:04:26 +0000132// --Commented out by Inspection START (06/02/2015 12:25):
133// public String getAndroidVersion(Resources resources)
134// {
135// String retVal = "";
136// if (!TextUtils.isEmpty(mAndroidVersion))
137// {
138// retVal = resources.getString(R.string.android) + " " + mAndroidVersion;
139// }
140// return retVal;
141// }
142// --Commented out by Inspection STOP (06/02/2015 12:25)
Filipe Gonçalvesb31d5862015-02-04 17:28:58 +0000143
Jose Pascoal1ee56e22014-05-21 16:58:20 +0100144 @Override
Filipe Gonçalvesb31d5862015-02-04 17:28:58 +0000145 public int compareTo(@SuppressWarnings("NullableProblems") Version another)
Jose Pascoal810950b2014-10-09 17:16:08 +0100146 {
Jose Pascoal1ee56e22014-05-21 16:58:20 +0100147 int retVal;
Jose Pascoal810950b2014-10-09 17:16:08 +0100148 if (another != null)
149 {
Maarten Derksbb287762015-10-12 17:22:45 +0200150 if (!this.getNumber().equals(another.getNumber()) && this.mImageType.equalsIgnoreCase(another.mImageType))
Jose Pascoal810950b2014-10-09 17:16:08 +0100151 {
Jose Pascoal1ee56e22014-05-21 16:58:20 +0100152 retVal = 1;
Jose Pascoal810950b2014-10-09 17:16:08 +0100153 }
Jose Pascoalcfc2dd42015-02-09 18:00:05 +0000154 else if (this.getNumber() == another.getNumber() && this.mImageType.equalsIgnoreCase(another.mImageType))
Jose Pascoal810950b2014-10-09 17:16:08 +0100155 {
Jose Pascoal1ee56e22014-05-21 16:58:20 +0100156 retVal = 0;
Jose Pascoal810950b2014-10-09 17:16:08 +0100157 }
158 else
159 {
Jose Pascoal1ee56e22014-05-21 16:58:20 +0100160 retVal = -1;
161 }
Jose Pascoal810950b2014-10-09 17:16:08 +0100162 }
163 else
164 {
Jose Pascoal1ee56e22014-05-21 16:58:20 +0100165 retVal = 1;
166 }
167 return retVal;
168 }
Tiago Costa6d360e22014-12-15 14:32:51 +0000169
Jose Pascoal40916302015-02-06 18:43:47 +0000170 public void setVersionDependencies(String dependencyList)
171 {
172 if (TextUtils.isEmpty(dependencyList))
173 {
174 mDependencies.clear();
175 }
176 else
177 {
178 String[] dependencies = dependencyList.split(DEPENDENCY_SEPARATOR);
179 for (String dependency : dependencies)
180 {
181 try
182 {
183 mDependencies.add(Integer.valueOf(dependency));
184 } catch (NumberFormatException e)
185 {
Jose Pascoalcfc2dd42015-02-09 18:00:05 +0000186 Log.e(TAG, "Invalid dependency: " + e.getLocalizedMessage());
Jose Pascoal40916302015-02-06 18:43:47 +0000187 }
188 }
189 }
190 }
191
Jose Pascoal060ab282015-02-09 19:56:08 +0000192// --Commented out by Inspection START (09/02/2015 19:47):
193// List<Integer> getVersionDependencies()
Jose Pascoal40916302015-02-06 18:43:47 +0000194// {
195// return mDependencies;
196// }
Jose Pascoal060ab282015-02-09 19:56:08 +0000197// --Commented out by Inspection STOP (09/02/2015 19:47)
Kim Hansen086964d2013-12-10 11:33:28 +0000198}